0

I'm using the following code in my subclass of UITableViewCell to set a drop shadow for unselected cells in my UITableView

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
{
  [super setHighlighted:highlighted animated:animated];
  [self applyLabelDropShadow:!highlighted];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
  [super setSelected:selected animated:animated];
  [self applyLabelDropShadow:!selected];
}

- (void)applyLabelDropShadow:(BOOL)applyDropShadow
{
  self.textLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : nil;
  self.textLabel.shadowOffset = CGSizeMake(0, 1);
  self.detailTextLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : nil;
  self.detailTextLabel.shadowOffset = CGSizeMake(0, 1);
}

This code from another StackOverflow question by Mike Stead and it works fine.

When the row moves from selected to deselected however, you can see the detailTextLabel shift down very slightly which I don't want to happen. This doesn't happen to the textLabel for the cell.

Any ideas why?

Community
  • 1
  • 1
conorgriffin
  • 4,282
  • 7
  • 51
  • 88

1 Answers1

2

Try using [UIColor clearColor] for the non-shadow instead of nil:

- (void)applyLabelDropShadow:(BOOL)applyDropShadow
{
  self.textLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : [UIColor clearColor];
  self.textLabel.shadowOffset = CGSizeMake(0, 1);
  self.detailTextLabel.shadowColor = applyDropShadow ? [UIColor whiteColor] : [UIColor clearColor];
  self.detailTextLabel.shadowOffset = CGSizeMake(0,1);
}
Richard Brown
  • 11,346
  • 4
  • 32
  • 43