【发布时间】:2017-06-17 12:11:17
【问题描述】:
有没有办法在tableView 上为每个其他单元格着色一种颜色?我尝试查看 tableView 的属性,但找不到任何东西。
我想要这样:
tableview
cell - white
cell - gray
cell - white
cell - gray
等等……
【问题讨论】:
有没有办法在tableView 上为每个其他单元格着色一种颜色?我尝试查看 tableView 的属性,但找不到任何东西。
我想要这样:
tableview
cell - white
cell - gray
cell - white
cell - gray
等等……
【问题讨论】:
一行代码,如果你愿意的话
cell.backgroundColor = indexPath.row % 2 == 0 ? .white : .gray
【讨论】:
最简单的方法是在您的 cellForRowAt 函数中以编程方式执行此操作:
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor.white
} else {
cell.backgroundColor = UIColor.gray
}
【讨论】: