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
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];
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!")
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