gpt4 book ai didi

ios - 为什么 UIColor.red 可以工作,但使用 UIColor 的初始值设定项却不行?

转载 作者:行者123 更新时间:2023-11-28 19:26:25 26 4
gpt4 key购买 nike

我在 View Controller 类中设置标签颜色。当我使用以下代码时,它起作用了。

self.labelTest.textColor = UIColor.red

enter image description here

但是,如果我使用 UIColor 的初始化程序,如下所示,标签将变为“不可见”。

self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0)

n

谁能告诉我为什么会这样?

最佳答案

这是因为你设置了alpha为0

self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0)

将 alpha 设置为 1 以使其可见

self.labelTest.textColor = UIColor(red: 1, green: 0, blue: 0, alpha: 1)

From documentation:

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.

关于ios - 为什么 UIColor.red 可以工作,但使用 UIColor 的初始值设定项却不行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54932117/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com