改变表格单元格中的uifont颜色

时间:2010-11-15 19:16:26

标签: iphone ios objective-c

我正在尝试使用以下代码更改单元格的颜色,但是它将所有单元格显示为白色字体,而不是我拥有的黄金rgb颜色代码。

if (row == 0)

    cell.detailTextLabel.text=@"An blah blah";
    cell.textLabel.textColor = [UIColor colorWithRed:139 green:136 blue:120 alpha:1];

3 个答案:

答案 0 :(得分:4)

你在错误的标签上设置它,这应该有效:

cell.detailTextLabel.text=@"An blah blah";
cell.detailTextLabel.textColor = [UIColor colorWithRed:139/255.0f green:136/255.0f blue:120/255.0f alpha:1];

答案 1 :(得分:1)

RGB参数在0到1范围内 将您的0-255值除以255。

if (row == 0)
    cell.detailTextLabel.text=@"An blah blah";
    cell.textLabel.textColor = [UIColor colorWithRed:139/255.0f green:136/255.0f blue:120/255.0f alpha:1];

另外,也许你的意思是detailTextLabel.textColor而不是textLabel.textColor。

答案 2 :(得分:0)

我不确定你是否为了这个例子,但你应该使用

if (indexPath.row == 0){
   cell.detailTextLabel.text=@"detailed text";  
   cell.textLabel.textColor = [UIColor colorWithRed:139/255.0f green:136/255.0f blue:120/255.0f alpha:1]; 
   return;
}