为什么 UIColor.red 有效但使用 UIColor 的初始值设定项却无效?
Why does UIColor.red work but using the initializer of the UIColor does not?
我正在视图控制器中设置标签颜色 class。当我使用以下代码时,它起作用了。
self.labelTest.textColor = UIColor.red
但是,如果我像下面这样使用 UIColor 的初始化程序,标签就会变成 "invisible"。
self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0)
谁能告诉我为什么会这样?
因为你设置了alpha为0
self.labelTest.textColor = UIColor(红:1,绿:0,蓝:0,alpha:0)
将 alpha 设置为 1 以使其可见
self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
alpha
The opacity value of the color object, specified as a value from
0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.
我正在视图控制器中设置标签颜色 class。当我使用以下代码时,它起作用了。
self.labelTest.textColor = UIColor.red
但是,如果我像下面这样使用 UIColor 的初始化程序,标签就会变成 "invisible"。
self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0)
谁能告诉我为什么会这样?
因为你设置了alpha为0
self.labelTest.textColor = UIColor(红:1,绿:0,蓝:0,alpha:0)
将 alpha 设置为 1 以使其可见
self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)
alpha
The opacity value of the color object, specified as a value from 0.0 to 1.0. Alpha values below 0.0 are interpreted as 0.0, and values above 1.0 are interpreted as 1.0.