I've added a text shadow to cells in my UITableView to give them an etched look:
cell.textLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.000];
cell.textLabel.shadowColor = [UIColor whiteColor];
cell.textLabel.shadowOffset = CGSizeMake(0, 1);
Since the shadow color is actually white, when a row gets selected and becomes blue, the white shadow becomes really visible and makes the text look ugly.
Does anyone know how I can remove the shadow before the default cell selection style gets applied?
I have tried:
- Using
-tableView:willSelectRowAtIndexPath:
to unset the shadow withcell.textLabel.shadowColor = nil
but this doesn't work in time - the shadow gets unset only after the blue select style is applied. - Checking
cell.selected
intableView:cellForRowAtIndexPath:
before setting the shadow but this obviously doesn't work since the cell is not redrawn after a selection.
I also tried overriding the -tableView:willDisplayCell:forRowAtIndexPath:
delegate method as Kevin suggested below. From logging statements I put in, this delegate method is only called just before a cell is drawn - by the time a cell is touched, it is already too late. This is the code I used
(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"in willDisplayCell");
if (cell.highlighted || cell.selected) {
NSLog(@"drawing highlighed or selected cell");
cell.textLabel.shadowColor = nil;
} else {
cell.textLabel.shadowColor = [UIColor whiteColor];
}
}