Objective-C: change text color of UIButton

To change the text color of UIButton is easy. Simply set preferred text color for each state:

[button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];

If the text color should state the same in all states, just connect the states with “|”:

[button setTitleColor:[UIColor redColor] forState:(UIControlStateHighlighted | UIControlStateNormal | UIControlStateSelected)];

And remember to change the type of UIButton from “System” to “Custom”. Otherwise the text color gets alpha value in highlighted state.