2
votes

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 then 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];   

}
3

3 Answers

10
votes

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;
}
2
votes

Yes that could be one way of doing it. If you want a "stateswitch" kind of look.

However you set the button.selected = YES;

1
votes

You probably want a UISegmentedControl instead. UIButton's are meant to be momentary.