【发布时间】:2014-02-22 10:23:25
【问题描述】:
我有一个动态的UITableview,我想为每个单元格设置不同的文本颜色。
我需要什么代码才能使文本颜色变为红色、黄色、绿色、蓝色?
【问题讨论】:
标签: uitableview text colors
我有一个动态的UITableview,我想为每个单元格设置不同的文本颜色。
我需要什么代码才能使文本颜色变为红色、黄色、绿色、蓝色?
【问题讨论】:
标签: uitableview text colors
下面的代码会帮助你
- (void)tableView: (UITableView*)tableView willDisplayCell: (UITableViewCell*)cell forRowAtIndexPath: (NSIndexPath*)indexPath
{
if(indexPath.row % 4 == 0)
cell.textLabel.textColor =[UIColor redColor];
else if(indexPath.row % 4 == 1)
cell.textLabel.textColor =[UIColor blueColor];
else if (indexPath.row % 4 == 2)
cell.textLabel.textColor =[UIColor yellowColor];
else if (indexPath.row % 4 == 2)
cell.textLabel.textColor =[UIColor greenColor];
}
【讨论】:
您需要一些代码来决定如何选择颜色。这可以是数组中的颜色和索引路径行的 mod (%) 以选择数组中的索引。然后,您想使用标签的textColor 或attributedText 属性来设置(属性)文本,包括颜色。
【讨论】: