【问题标题】:TableView every other cell one colorTableView每隔一个单元格一种颜色
【发布时间】:2017-06-17 12:11:17
【问题描述】:

有没有办法在tableView 上为每个其他单元格着色一种颜色?我尝试查看 tableView 的属性,但找不到任何东西。

我想要这样:

tableview
 cell - white
 cell - gray
 cell - white
 cell - gray

等等……

【问题讨论】:

标签: swift colors tableview


【解决方案1】:

一行代码,如果你愿意的话

 cell.backgroundColor = indexPath.row % 2 == 0 ? .white : .gray

【讨论】:

    【解决方案2】:

    最简单的方法是在您的 cellForRowAt 函数中以编程方式执行此操作:

    if indexPath.row % 2 == 0 {
        cell.backgroundColor = UIColor.white
    } else {
        cell.backgroundColor = UIColor.gray
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-07-15
      • 2015-11-29
      • 2014-12-30
      • 1970-01-01
      • 2022-10-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多