3 回答
TA贡献1866条经验 获得超5个赞
UIColor的RGB值介于0和1之间(请参阅文档 “指定为0.0到1.0之间的值”)
你需要将你的数字除以255:
passwordTextField.textColor = UIColor(red: CGFloat(202.0/255.0), green: CGFloat(228.0/255.0), blue: CGFloat(230.0/255.0), alpha: CGFloat(1.0))
另外,你不需要创建CGFloats:
passwordTextField.textColor = UIColor(red:202.0/255.0, green:228.0/255.0, blue:230.0/255.0, alpha:1.0)
TA贡献1827条经验 获得超7个赞
使用方便init(代码像专业人士)
步骤1
extension UIColor {
convenience init(r: CGFloat, g: CGFloat, b: CGFloat) {
self.init(red: r/255, green: g/255, blue: b/255, alpha: 1)
}
}
用法
//let color = UIColor(red: 202/255, green: 228/255, blue: 230/255, alpha: 1) ☠️
let color = UIColor(r: 202, g: 228, b: 230) // ?
TA贡献1801条经验 获得超15个赞
试试这个:
passwordTextField.textColor = UIColor(red: 0.792, green: 0.894, blue: 0.901, alpha: 1.0
始终放置替代值。202/255 = 0.792
- 3 回答
- 0 关注
- 628 浏览
添加回答
举报