【发布时间】:2015-07-07 08:24:44
【问题描述】:
我创建了一个UIButton 的实例,并希望为Normal 状态、Selected 状态和Highlighted 状态设置标题颜色。我这样做是因为-
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState: UIControlStateSelected];
[button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
使用上面的代码,当我构建和运行应用程序时,文本按预期显示为红色。
但是当我将一个语句中所有状态的按钮标题颜色设置为 -
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal | UIControlStateSelected | UIControlStateHighlighted];
构建并运行应用程序...
问题
按钮上的文字显示为白色。
这(上述语句)不是设置UIButton 的标题颜色的正确方法吗?我需要在三个不同的语句中设置UIButton 的标题颜色吗?
感谢任何建议/帮助!
非常感谢。
【问题讨论】:
-
来自您的尝试:
In general, if a property is not specified for a state, the default is to use the UIControlStateNormal value. If the UIControlStateNormal 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.
标签: ios objective-c cocoa-touch uibutton uicolor