Highlight color for UITableViewCell

If I have a custom UITableViewCellone that does not use the textLabelbuilt-in cell, but instead makes its own drawing, how can I change the appearance contentViewwhen I select how this happens automatically for the default text (configured by the installation selectedTextColor:)?

If I change tableView:willSelectRowAtIndexPath:, it is updated only after the blue background of the selection is up, but not during the animation as I want.

+3
source share
3 answers

Just do not subclass UITableViewCell and do not use the default behavior. You can fully customize the cell without any subclass.

Read this article for more details .

+6
source

Add this code to your cellForRowAtIndexPath method and simply change the expected color for the UITableViewCell select style.

   //-------------------------------------------------------------------------
   //background selected view 
   UIView *viwSelectedBackgroundView=[[UIView alloc]init];
   viwSelectedBackgroundView.backgroundColor=[UIColor colorWithRed:124.0/255.0 green:202.0/255.0 blue:227.0/255.0 alpha:1.0];
   cell.selectedBackgroundView=viwSelectedBackgroundView;
   //-------------------------------------------------------------------------
+5
source

If you have subclassed UITableViewCell, you can customize the cell elements by overriding the following:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
    if(highlighted) {
        self.backgroundColor = [UIColor redColor];
    } else {
        self.backgroundColor = [UIColor clearColor];
    }

    [super setHighlighted:highlighted animated:animated];
}
+3
source

Source: https://habr.com/ru/post/1710629/


All Articles