ios - 当 6 出现在 UITableView 时,如何重用这些数字背景颜色 1-5?

标签 ios swift uitableview

我为此使用 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)

Image

最佳答案

问题是单元格重用,你应该有一个包含每行渐变颜色的模型数组并将其设置在 cellForRow

关于ios - 当 6 出现在 UITableView 时,如何重用这些数字背景颜色 1-5?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49707271/

相关文章:

swift - NSNotificationCenter userInfo 中的字典值类型

swift - 通过点击关闭键盘时丢弃输入

ios - 处理 TableView 内容

ios - 使一个单元格(但不是第一个单元格)在 UITableView 上始终可见

ios - 如果在JSON对象中加载了空图片网址,则应用崩溃

ios - iPad 2/Retina iPad,应用程序如何识别它在哪个设备上运行?

ios - 将索引路径发送到 Firebase(如按钮)

iphone - 弹出窗口的屏幕截图不清晰

swift - 辛格尔顿?或者,还有更好的方法?

android - 如何在 React Native 中开发时间轴屏幕