将 UIColor 转换为 CGColor 时颜色错误

Wrong color when convert UIColor to CGColor

当我将 UIColor 转换为 CGColor 时,我没有得到正确的颜色。

这个颜色:

 let color = UIColor(red: 198, green: 35.0, blue: 80.0, alpha: 1.0)

当我将它应用到 CAlayer 上时

layer.fillColor = UIColor.red.cgColor
layer.strokeColor = color.cgColor

将出现在我的 phone !

white

如您所见,圆圈是白色的...

Colors in UIKit are specified using value is between 0 and 1 in float not int from 0 to 255, so you need to divide all your RGB values by 255.0.

let color = UIColor(red: 198.0/255.0, green: 35.0/255.0, blue: 80.0/255.0, alpha: 1.0)