小编Irs*_*shi的帖子

UITableView中的颜色交替UITableViewCell?

我试图使用此链接将表格视图中的替换tableCell 着色为此代码的颜色单元格:

func colorForIndex(index: Int) -> UIColor 
{

    let itemCount = stnRepos.count - 1
    let color = (CGFloat(index) / CGFloat(itemCount)) * 0.6
    return UIColor(red: 0.80, green: color, blue: 0.0, alpha: 1.0)
}

func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell,
    forRowAtIndexPath indexPath: NSIndexPath) 
{
        var count = stnRepos.count
        for (var i = 0; i<=count; i++)
        {
            if (i % 2 == 0)
            {
                cell.backgroundColor = colorForIndex(indexPath.row)
                println(i)
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

但最终着色所有单元格,如链接所示.

uitableview ios uibackgroundcolor swift

3
推荐指数
1
解决办法
5447
查看次数

标签 统计

ios ×1

swift ×1

uibackgroundcolor ×1

uitableview ×1