Objective-c – UIButton state selected

objective cstateuibutton

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

}

Best Answer

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