【问题标题】:How to set different text colours on uitableviews如何在 uitableviews 上设置不同的文本颜色
【发布时间】:2014-02-22 10:23:25
【问题描述】:

我有一个动态的UITableview,我想为每个单元格设置不同的文本颜色。

我需要什么代码才能使文本颜色变为红色、黄色、绿色、蓝色?

【问题讨论】:

    标签: uitableview text colors


    【解决方案1】:

    下面的代码会帮助你

    - (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];
    }
    

    【讨论】:

      【解决方案2】:

      您需要一些代码来决定如何选择颜色。这可以是数组中的颜色和索引路径行的 mod (%) 以选择数组中的索引。然后,您想使用标签的textColorattributedText 属性来设置(属性)文本,包括颜色。

      【讨论】:

        猜你喜欢
        • 2012-03-14
        • 1970-01-01
        • 2015-06-01
        • 1970-01-01
        • 1970-01-01
        • 2012-06-12
        • 2021-01-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多