更改空表视图单元格的备用单元格backgroundcolor

时间:2017-07-01 06:43:25

标签: swift tableviewcell

我在swift4中以编程方式创建了一个tableview控制器。我的观点目前看起来像这样 enter image description here

我希望在未使用的表格视图单元格中的图像中标记备用灰色。我可以更改使用的表格视图单元格的替代颜色。 任何帮助都非常感谢。

1 个答案:

答案 0 :(得分:0)

你在tableView中试过这个吗(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) - >的UITableViewCell:

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

它对我有用。我希望这也适合你。