I need UIButton to support pressed state. In principle, if the button is in normal condition, I want to touch the button, it is highlighted in standard blue, and then remains blue after raising a finger. I did the following UIAction and connected the Touch Up Inside buttons to it.
-(IBAction) emergencyButtonPress:(id) sender
{
if(emergencyButton.highlighted)
{
emergencyButton.selected = NO;
emergencyButton.highlighted = NO;
}
else
{
emergencyButton.selected = YES;
emergencyButton.highlighted = YES;
}
}
But what happens, after I remove my finger, the button returns to a white background. For the test, I added UISwitch and executed the same code:
-(IBAction) emergencySwitchClick:(id) sender
{
if(emergencyButton.highlighted)
{
emergencyButton.selected = NO;
emergencyButton.highlighted = NO;
}
else
{
emergencyButton.selected = YES;
emergencyButton.highlighted = YES;
}
}
In this case, the button switches to the highlighted and unselected state, as I expected.
Was there another event after the Touch Up Inside event that returns the state to its normal state? How to save the selected state?
source