Install UIButton image in interface builder for differen state

I have a very strange problem.

In the interface builder, I try to set the images for the โ€œnormalโ€ configuration state and for the โ€œselectedโ€ configuration state. but by clicking the button, my image will not be resized.

even I write code in the viewDidLoad method.

[btnCheckBoxMale setImage:[UIImage imageNamed:@"blankcheckbox.png"] forState:UIControlStateNormal]; [btnCheckBoxMale setImage:[UIImage imageNamed:@"checkbox.png"] forState:UIControlStateSelected]; 

but my images do not change when clicking on it

can anyboday say what is the problem?

+4
source share
4 answers

just set the selected one when you call the method when the button is clicked .. for example.

 -(IBAction) btnCheckBoxMale_Clicked:(id)sender{ [btnCheckBoxMale setSelected:YES]; } 
0
source

Set the image in different states in the interface builder instead of setting it in code. See a screenshot of how to install it. Try this, and if you encounter any problem, ask me. button image

+28
source

It will work if you manually set the button action:

 btnCheckBoxMale.selected = YES; 

Because by default, UIButton has only two states - Normal and Highlighted. And other states, such as selected and disabled , you must manage manually.

+3
source
 -(IBAction) btnCheckBoxMale_Clicked:(id)sender{ UIButton * btnCheckBoxMale = (UIButton *)sender; [btnErase setSelected:! btnCheckBoxMale]; } 
0
source

All Articles