bkbeachlabs
bkbeachlabs

Reputation: 2171

iphone button text color changes by itself when clicked?

Im trying to troubleshoot my first iphone app and Ive run into a propblem i just dont get. I have lots of buttons on a view and when you click them their text colour changes from black to blue. I assume that I could fix this by just setting the textColor property every time the button gets pushed to set it back to black but I feel like there must be something else going on.

Anyone know why my buttons are changing color by themselves?

Upvotes: 0

Views: 3702

Answers (1)

lukasz
lukasz

Reputation: 771

It is possible to have different title colors depending on button state. Set them using the following method of the UIButton class:

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

F.e.

[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];

where UIControlStateNormal is the default, not pressed, button state, and forState:UIControlStateHighlighted represents the pressed state. But there are more, and can be combined with binary sum, such as (UIControlStateHighlighted | UIControlStateSelected).

Upvotes: 3

Related Questions