我为此使用 UITableView,它为每个单元格添加 1 个数字并更改背景颜色。你能告诉我如何在 5 号之后重复使用这些颜色吗?当单元格 6 显示时,它开始显示从 1 开始的颜色。
//Gradient Color in cell
let gradientLayer1 = CAGradientLayer()
let colorTop = UIColor.rgb(r: 247, g: 121, b: 133).cgColor
let colorBottom = UIColor.rgb(r: 251, g: 159, b: 168).cgColor
gradientLayer1.colors = [ colorTop, colorBottom]
gradientLayer1.frame = cell.viewNumber.bounds
cell.viewNumber.layer.insertSublayer(gradientLayer1, at: 0)
最佳答案
问题是单元格重用,你应该有一个包含每行渐变颜色的模型数组并将其设置在 cellForRow
关于ios - 当 6 出现在 UITableView 时,如何重用这些数字背景颜色 1-5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49707271/