2012-05-15 51 views
0

我想更改UITableViewCell的initWithStyle方法中的UILabel文本顏色。但顏色沒有變化。 但是,當在cellForRowAtIndexPath方法中完成顏色更改時,顏色會發生變化。爲什麼?自定義單元格標籤文本顏色

+3

你可以請把你寫在cellForRowAtIndexPath中的代碼? –

+0

請參閱initwithStyle中的代碼。並告訴我們,如果你正在使用故事板和原型單元格。 – jrturton

回答

0

取決於你如何使用您的標籤,你只需要設置textColor屬性:

對於- (UITableViewCell*)tableView:(UITableView *)tableView方法創建tableViewCell我認爲你已經使用類似以下內容:

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"]; 

有可能的可能性,你你的風格是UITableViewCellStyleDefaultUITableViewCellStyleValue1 or UITableViewCellStyleValue2 or UITableViewCellStyleSubtitle`。

現在什麼風格,你正在使用,如果您要添加您自己的標籤比使用:

UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10,10,100,25)]; 
lbl.text = @"your Text"; 
[lbl setTextColor:[UIColor greenColor]]; 

,如果你不加入自己的標籤和使用默認標籤是textLabelUITableViewCell對象的detailTextLabel

[cell.textLabel setTextColor:[UIColor greenColor]]; 
[cell.detailTextLabel setTextColor:[UIColor greenColor]]; 

如果要添加任何標籤的子視圖,如:

UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(10,10,100,25)]; 
lbl.text = @"your Text"; 
[lbl setTextColor:[UIColor greenColor]]; 

你可以用你想要的顏色代替greenColor。 希望這有助於:)

相關問題