2012-03-04 91 views
0

选中时UITableView中文本的默认颜色为白色。我想把它改成深灰色。我设法这样做是为了改变主标题标签文本:突出显示更改UITableView cell.detailTextLabel颜色

cell.selectedTextColor = [UIColor darkGrayColor]; 

我怎样才能为detailTextLabel做到这一点,虽然当它被高亮显示/选择?

谢谢

回答

4

您可以继承UITableViewCell。然后覆盖setHighlighted:动画方法:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated { 
     [super setHighlighted:highlighted animated:animated]; 
     if (highlighted) { 
      self.detailTextLabel.textColor = [UIColor lightGrayColor]; 
     } else { 
      self.detailTextLabel.textColor = [UIColor whiteColor]; 
     } 
} 

您可能最终想要覆盖setSelected:animated方法。

+0

感谢,但它不承认cell.detailTextLabel? – 2012-03-04 20:50:27

+0

有关于此的任何想法? – 2012-03-05 07:23:42

0
cell.detailTextLabel.textColor = [UIColor blue color]; 
+2

这只会将默认状态下的detailTextLabel颜色更改,而不会突出显示。 – Keller 2012-03-04 20:50:58

+1

更正:[UIColor blueColor] – 2013-05-11 07:59:59

1

只需使用:

cell.detailTextLabel.highlightedTextColor = [UIColor blueColor];