如何更改UIButton的LabelText颜色?

cgo*_*ain 3 uibutton ipad ios4

嗨,我正在以编程方式创建一个UIButton,我正在尝试将按钮的textLabel的文本颜色更改为橙​​色.我在下面尝试了两行,但它们没有用.有人能告诉我如何正确地做到这一点.

[myButton.titleLabel setTextColor:[UIColor orangeColor]];
Run Code Online (Sandbox Code Playgroud)

和,

myButton.titleLabel.textColor = [UIColor orangeColor];
Run Code Online (Sandbox Code Playgroud)

Pen*_*One 13

请尝试使用- (void)setTitleColor:(UIColor *)color forState:(UIControlState)state:

[myButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
Run Code Online (Sandbox Code Playgroud)

这里的问题是UIButton的titleLabel是只读的,虽然它的属性不是.这就是为什么你看似正确的代码不起作用的原因.