2013-03-02 112 views
0

我使用下面的代码在我的UITableViewCell子类从另一个StackOverflow question通过Mike Stead设置选定单元阴影在我UITableView为什么我的detailTextLabel正在移动?

- (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); 
} 

此代码,它工作正常。

然而,当行从选择移动到取消选择,但你可以看到detailTextLabel轻微下移,我不希望发生。这不会发生在单元格的textLabel

任何想法为什么?

回答

2

尝试使用[UIColor clearColor]对于非阴影,而不是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); 
} 
+0

问题解决了,但为什么没有发生在'textLabel'用相同的代码? – conorgriffin 2013-03-02 16:35:50

+0

它可能是一个像素边界问题,其中textLabel的大小与detailTextLabel的大小不同。一个像素偏移影响一个可见而不是另一个。 – 2013-03-02 16:37:20

+0

有道理,接受你的答案。必须等待强制性冷却期... – conorgriffin 2013-03-02 16:38:38

相关问题