【发布时间】:2020-09-07 14:17:48
【问题描述】:
var CodeBackground = #colorLiteral(red: 0.1294117647, green: 0.1294117647, blue: 0.1960784314, alpha: 1)
cells?.layer.borderColor = //... how can i set this color literal to cgColor?
我知道如何在 Swift 中将该 UIColor 转换为 cgColor
举例
UIColor.black.cgColor
宾果游戏,但是 Swift 中的颜色文字到 cgColor 呢
谢谢。
【问题讨论】:
-
完全一样的东西
whatever.cgColor。 dropbox.com/s/xxd6nw06z1adxzq/color%20literal.jpg?dl=1顺便说一句,Swift 命名约定以小写字母开头的对象命名。 -
这仍然是个问题,我跑到 iOS 模拟器并拒绝显示颜色。 (除非您创建多个单元格可能会在您向下滑动以通过该单元格并向上滑动时产生错误,并且从不同的单元格中它是相同的)。我只需要设置 UIColor,但是该代码显示错误,要求从 UIColor 使用 cgColor....看起来很奇怪。
-
细胞可重复使用
-
表格视图有一个方法叫
optional func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath)表格视图一结束显示就可以清除单元格内容 -
事情很简单,使用如下:viewBack.layer.borderColor = #colorLiteral(red: 0.05882352963, green: 0.180392161, blue: 0.2470588237, alpha: 1).cgColor//UIColor.white
标签: swift uitableview uicolor cgcolor