2013-03-02 61 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

相關問題