我想通过代码设置 UIButton 的标题。我发现自己必须为 UIControlStateNormal、UIControlStateHighlighted、UIControlStateDisabled、UIControlStateSelected 调用 -[UIButton setTitle:forState:]。这甚至没有考虑到这些状态的所有组合。
不用说,这很烦人。我是否可以进行一次调用,将一个字符串设置为所有州的标题? (因为,我假设在 95% 的情况下,这是期望的行为?)
最佳答案
是的,你当然可以。 From the docs :
In general, if a property is not specified for a state, the default is to use the
UIControlStateNormal
value. If the value forUIControlStateNormal
is not set, then the property defaults to a system value. Therefore, at a minimum, you should set the value for the normal state.
因此,只需设置 UIControlStateNormal
的标题即可。
关于iphone - 使用单个方法调用设置 UIButton 的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2479513/