Al_fareS
Al_fareS

Reputation: 725

UIButton doesn't want to keep in Selected State when clicking on the button

I am trying to figure out what's wrong here, because as you can in the screenshots a different image is given for both, selected and default state.

The problem :

when I run on simulator, I click on the button, it shows the image of highlited state, and then back to the normal state without keeping changed at the selected state ! any hints or ideas about this particular issue ?

Normal State

Selected State

Upvotes: 3

Views: 1443

Answers (2)

Anessence
Anessence

Reputation: 589

You should manually set selected state to YES in code when the button is pressed

- (IBAction)btnTapped:(UIButton*)button {
    button.selected = !button.selected; // to switch from selected to unselected and vice versa
}

Upvotes: 5

santhu
santhu

Reputation: 4792

I think you should add a target to this button and in that method, you should write

button.selected=YES;  //then only the image will change.

Upvotes: 1

Related Questions