How to change LabelText UIButton color?

Hi, I am creating a UIButton programmatically and I am trying to change the text color of the textLabel button to orange. I tried both lines below, but they do not work. Can someone tell me how to do it right.

[myButton.titleLabel setTextColor:[UIColor orangeColor]];

and

myButton.titleLabel.textColor = [UIColor orangeColor];
+3
source share
1 answer

Try using instead - (void)setTitleColor:(UIColor *)color forState:(UIControlState)state:

[myButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];

The problem here is that the UIButton titleLabel is read only, although its properties are not. That is why your seemingly correct code does not work.

+13
source

All Articles