Note that there are some explanatory texts on larger screens.

plurals
  1. PORemoving text shadow in UITableViewCell when it's selected
    text
    copied!<p>I've added a text shadow to cells in my UITableView to give them an etched look:</p> <pre><code>cell.textLabel.textColor = [UIColor colorWithWhite:0.2 alpha:1.000]; cell.textLabel.shadowColor = [UIColor whiteColor]; cell.textLabel.shadowOffset = CGSizeMake(0, 1); </code></pre> <p>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.</p> <p>Does anyone know how I can remove the shadow before the default cell selection style gets applied?</p> <p>I have tried:</p> <ol> <li>Using <code>-tableView:willSelectRowAtIndexPath:</code> to unset the shadow with <code>cell.textLabel.shadowColor = nil</code> but this doesn't work in time - the shadow gets unset only after the blue select style is applied.</li> <li>Checking <code>cell.selected</code> in <code>tableView:cellForRowAtIndexPath:</code> before setting the shadow but this obviously doesn't work since the cell is not redrawn after a selection.</li> </ol> <p>I also tried overriding the <code>-tableView:willDisplayCell:forRowAtIndexPath:</code> 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</p> <pre><code>(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]; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload