2012-03-04 177 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]; 
相關問題