Change highlighting of certain subviews in a UITableViewCell

uitableviewcell highlight color
uitableviewcell highlight color swift
uitableviewcell highlight on touch
uitableviewcell not highlighting
change uitableviewcell color swift
uitableviewcell selectedbackgroundview
uitableviewcell setselected
uitableviewcell selection style

Is it possible to exclude certain subviews in a UITableViewCell from being highlighted or to change their highlight implementation?

I added an orange warning label to the UITableViewCell for certain occassions and it highlights properly with the rest of the cell, which is good. However, when the cells stops being highlighted in an animated way, you first see the background of the warning label become white and then flash to orange. I would either like it to be excluded from being highlighted at all, or to change it's highlight implementation so it animates back to orange properly.

It doesn't seem to be possible to exclude views from being highlighted if the superview calls for it. However, overriding their setHighlighted: can give the same result if you just stop any highlighting behavior there or change it to your specifications.

Is it possible to exclude certain subviews in a UITableViewCell from being highlighted or to change their highlight implementation? I added an orange warning  The “Prep Time” is a static label that only displays the text of “Prep Time:”. Lastly, the “Time” label is a dynamic label that is used to show the actual preparation time for the specific recipe. To add a label, select “Label” in Object library and drag it to cell. You can double click the label to change its name.

In iOS 6, you can use 2 methods in UITableViewDelegate to customise highlighting for the cell, and also it subviews:

- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setBackgroundColor:[UIColor lightGrayColor]];
}

- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [UIView animateWithDuration:0.5f animations:^{
        [cell setBackgroundColor:[UIColor whiteColor]];
    }];
}

I did not show the code for changing the subviews.

But you can do similarly like the way you configure for each cell, using cell viewWithTag to access the subview, then change the background or any other properties.

For selected cells, add your subviews to contentView as before: Override Changes to UITableViewCells in iPhone OS 3.0 Apple decided to rearchitect Beginning with iPhone OS 3.0, UIImageView supports a highlighted property that​  Accessory views are often used with standard UITableViewCellAccessory s, such as a checkmark or disclosure indicator. When being edited, a UITableViewCell will combine its ContentView with an editing control on the left and, optionally, a reordering control on the right.

You cannot remove certain subviews from animating, but you can change some behaviors as follow:

Avoid the UITableViewCell from doing a highlighting animation like this:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

When a cell is selected, do manual changes to background like this example:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

    [cell setBackgroundColor:[UIColor purpleColor]];

    [UIView animateWithDuration:0.5f animations:^{
            [cell setBackgroundColor:[UIColor clearColor]];
    }];

}

I had a simple UITableView and this worked as I needed.

Why UITableViewCell highlight and selection styling are such a mystery? When the selected state of a cell is YES, it draws the background for Setting images for each selection state to just change colors feels bruteforce. Subviews in UITableViewCell's containView are not added into the UI hierarchy in iOS9 667 Views 5 Replies Latest reply on Sep 3, 2015 7:55 AM by PLYdev

in order to have a custom highlight behavior on a table view cell, override setHighlighted method and parse highlighted:false in to the super method, and customize specify which views should change color based on highlight property below

However, for my ShopLater app, I wanted the selected cell to be pink! of a UITableViewCell is actually a background color on a subview of the cell. So, to change the selection color, simply assign a different selection view to  Basically the the selection color of a UITableViewCell is actually a background color on a subview of the cell. So, to change the selection color, simply assign a different selection view to the selected background view of your cell in your code! 1. 2.

When the cell is asked to stop being highlighted/selected, our code retrieves the original colors of swap the two methods as shown below: [UITableViewCell  disable the uitableview highlighting but allow the selection of individual cells (8) . when you tap on a cell the row gets selected and highlighted.Now what i want to do is disable the highlighting but allow the selection.Is there a way around it.There is question that answers this but it disables both the selection and highlighting.

Or is the intent here to hide the color change? As for a more concrete review of some of the code you have, this function: private func backgroundColors  UITableViewCell highlighting does not change the color of DVColorLockViews. DVColorLockView overides the backgroundColor setter for UIView. Highlighting a UITableViewCell changes the background color of all it's subviews, it's annoying. Highlighting a UITableViewCell won't change the color of its DVColorLockView subviews.

The UITableViewCell class no longer changes the backgroundColor or and any of its subviews when cells become highlighted or selected. You use cells primarily to organize and present your app’s custom content, but UITable View Cell provides some specific customizations to support table-related behaviors, including: Applying a selection or highlight color to the cell. Adding standard accessory views, such as a detail or disclosure control. Putting the cell into an editable state.

Comments
  • So far I have figured out that overriding setHighlight:animated: and returning immediately cancels out starting highlighted. But the highlight when I press the cell still turns the lable blue.
  • There has been similar issues elsewhere as well. I posted an answer here stackoverflow.com/a/36886209/81388.