UIButton title color change on highlight - How to turn it off?
As @null points out, by far the simplest way to do this is to set the button type in Interface Builder (or in code) to "Custom".
If you need to replicate this behavior with a standard button, override the setHighlighted
method to prevent the alpha channel of the titleLabel from adjusting too:
- (void)setHighlighted:(BOOL)highlighted
{
[super setHighlighted:highlighted];
self.titleLabel.alpha = 1.0;
}
you can use
[UIButton setTitleColor:forState:]
for all the states , then title color will remain same for all states.
[button setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor redColor] forState:UIControlStateSelected];
Note:To avoide type or paste above code three times you can use following code suggested by Will,
[button setTitleColor:[UIColor redColor] forState:(UIControlStateHighlighted | UIControlStateNormal | UIControlStateSelected)];
0 lines of code:
Using Interface Builder and either .XIB
or .storyboard
, select your UIButton
in IB:
View > Utilities > Show Attributes Inspector.
Select State Config (Default) to one of Highlighted, Selected or Disabled and change the Text Color attribute.
There are a few comments pointing this out, but in order to have it as an actual answer:
Set the button type to Custom
in your storyboard or in code:
[UIButton buttonWithType:UIButtonTypeCustom];