【发布时间】:2020-07-01 17:11:32
【问题描述】:
您好,我是 IOS 开发新手。我正在尝试为每个 tableview 单元格提供不同的十六进制颜色。以下更改 contentView 颜色的代码无济于事。
var cellColors = ["F28044","F0A761","FEC362","F0BB4C","E3CB92","FEA375"]
func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! CustomCells
cell.contentView.backgroundColor = UIColor(named: cellColors[indexPath.row % cellColors.count])
}
【问题讨论】:
-
您能解释一下“以下代码更改 contentView 颜色没有帮助吗?”它怎么没有帮助?它在做什么是错的?你到底想让它做什么?在此处需要更多信息
标签: ios swift uitableview swift5