I've seen a lot of info on changing the button image for selected but being a new I'm having a bit of trouble implementing a simpler version of it.
When the button is pressed it goes dark and I would like it to stay that way once it's been selected. So there are a few questions.
Do I create IBOutlet for the button and th开发者_高级运维en and IBAction to change the state with something like button.state = SELECTED.
Sorry for the complete lack of any code to look at.
Edit: (id)sender is the button object right?
-(IBAction)journalEntryViewControllerClick: (id)sender
{
UIButton *button = (id)sender;
[button setSelected:YES];
}
You can set separate image for button's selected state (UIControlStateSelected) and in button action you can toggle its state:
- (void) btnAction:(UIButton*)button{
button.selected = !button.selected;
}
Yes that could be one way of doing it. If you want a "stateswitch" kind of look.
However you set the button.selected = YES;
You probably want a UISegmentedControl
instead. UIButton
's are meant to be momentary.
精彩评论