I have an UIButton configured with two states, default and selected, for different text and background, the set up is done on Interface Builder. The weird thing is when the button is in selected state, and the button is pressed, it automatically changes to default state. After the button is released, it changes back to selected state. Is there way to disable roll-back-to-default behavior?
Forgot to mention that, the type is custom
.
tried the following code in viewDidLoad
[self.button setTitle:@"default" forState:UIControlStateNormal];
[self.button setTitle:@"selected" forState:UIControlStateSelected];
[self.button setTitle:@"highlighted" forState:UIControlStateHighlighted];
[self.button setSelected:YES];
The button shows default when pressed.
Selected state and Highlighted state are not mutually exclusive. When you press a selected UIButton, it gets into a selected AND highlighted state.
I don't think there's a way to set that in the IB, but you can do this in code:
[button setImage:[UIImage imageNamed:@"some_image"] forState:UIControlStateSelected | UIControlStateHighlighted];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With