I have a standard UITableView. I want to set the shadowColor cell to [UIColor whiteColor] , but only when the cell is touched. For this, I use the following code. This is a custom subclass of UITableViewCell that overrides setSelected / setHighlighted:
@implementation ExampleTableViewCell - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; [self setShadowColorSelected:selected]; } - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { [super setHighlighted:highlighted animated:animated]; [self setShadowColorSelected:highlighted]; } - (void)setShadowColorSelected:(BOOL)selected { if (selected) { self.textLabel.shadowColor = [UIColor blackColor]; }else { self.textLabel.shadowColor = [UIColor whiteColor]; } } @end
My problem with this approach is that when deselecting, the cell has a very short period when both the label text and the shadow are white. See this screenshot at the exact time. Cancel selection:

Basically the same approach as in these two posts:
UILabel shadow of the selected color of the selected cell
Remove text shadow in UITableViewCell when it is selected
I use the accepted answer approach in the last question.
I created a very simple code project and uploaded it to github . This shows my problem. This is just a UITableViewController that displays a single cell.
Also, nothing out of the ordinary. UITableView delegate methods:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (!cell) { cell = [[ExampleTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } cell.textLabel.text = @"test"; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
Any ideas?
source share