Reputation: 33674
Is there any way to keep track the state of a UIButton whether it is selected or not? I tried accessing the selected property but it doesn't seem to work, seems to work only for UISwitch
Upvotes: 4
Views: 14602
Reputation: 450
Yes some UIButtons can have a selected state, which may only be momentary. However UIButtons inherit from UIControls which have a selected property. You can query to see if you button is selected using:
if([myButton isSelected])
NSLog(@"Selected!")
Upvotes: 2
Reputation: 38728
You need to set the state to selected if you want to use it like a toggle
- (void)buttonTapped:(UIButton *)button;
{
button.selected = ![button isSelected];
}
then you can just query it like normal
[self.button isSelected];
Upvotes: 10
Reputation: 16089
What do you mean by “selected”? In standard usage, UIButtons only have three states: normal, disabled, and active, where “active” means “being tapped right now”. They’re not sticky.
Upvotes: 0