Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom UITableViewCell selection style?

When I click on my UITableViewCell, the background part (the areas that my background image doesn't cover) turns blue when I click on the cell. Also, all of the UILabels on the cell turn to white when it is clicked which is what I want.

However what I do not want is the blue background when I click it but if I do selectionstylenone, then I lose the highlighted colours for the UILabels in the cell.

So is there any way to just get rid of the blue background when the cell is clicked but to keep the highlighted colors of the UILabels?

like image 447
SimplyKiwi Avatar asked Aug 12 '12 06:08

SimplyKiwi


1 Answers

You can do this as follows. Set your table cell's selection style to UITableViewCellSelectionStyleNone. This will remove the blue background highlighting. Then, to make the text label highlighting work the way you want, instead of using the default UITableViewCell class, create a subclass of UITableViewCell and override the default implementation of setHighlighted:animated with your own implementation that sets the label colors to however you want depending on the highlighted state.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {     if (highlighted) {         self.textLabel.textColor = [UIColor whiteColor];     } else {         self.textLabel.textColor = [UIColor blackColor];     } } 
like image 168
jonkroll Avatar answered Sep 19 '22 07:09

jonkroll