gpt4 book ai didi

ios - 配置对象时 `UIControlState()`和 `UIControlState.normal`有什么区别

转载 作者:IT王子 更新时间:2023-10-29 05:33:50 24 4
gpt4 key购买 nike

我经常看到使用 UIControlState.normal,例如在 UIButton 对象上设置一个 titleColor,它将在所有控件状态中使用,作为 UIButton。 setTitleColor 文档说:

In general, if a property is not specified for a state, the default is to use the normal value. If the normal value is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.

但我也发现正在使用 UIControlState.init(),例如以下行:

UIButton.setTitleColor(UIColor, for: UIControlState())

想知道它有何不同,在此先感谢!

最佳答案

UIControlState.normal 是表示“正常”状态的特定控件状态。

UIControlState() 是一个“空”控件状态,带有一些未记录的默认值。

碰巧这两个都由原始值 0 支持。所以看起来两者都代表了“正常”状态。

但是依靠这个是不好的做法。默认值可能会更改。最好使用所提供的具体的、明确记录的值。

始终使用 UIControlState.normal 作为“正常”状态。切勿使用 UIControlState(),因为它的值未记录并且无法保证它始终具有与 UIControlState.normal 相同的基础值。

关于ios - 配置对象时 `UIControlState()`和 `UIControlState.normal`有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45662507/

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