How can I change the color of the text on my UIButton. Here is my current code:
UIButton *b1 = [[UIButton alloc] init];
b1.frame = CGRectMake(280,395
The reason your original code wasn't working is because you were passing in a UIControlEvents
parameter instead of a UIControlState
parameter.
[b1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
That will set the color for the normal state, and, unless you set colors for other states, it will persist across all states. To change the color for the other states, just call the same method with other states (UIControlStateNormal
, UIControlStateHighlighted
, UIControlStateDisabled
, UIControlStateSelected
):
[b1 setTitleColor:[UIColor blueColor] forState:UIControlStateSelected];
Try setting the individual events, such as:
[b1 setTitleColor:[UIColor redColor] forState:UIControlStateNormal];