user1511244 user1511244 - 1 year ago 93
iOS Question

How to change background image on a button , iOS?

I created a button on my view controller which has a predefined background image. I created an action and an outlet for this button. I want when the user taps the button to change the background image of this button. How can i do that?
I tried to put into the action method of the button something like this:

snapshotCheckbox.image = [UIImage imageNamed:@"snapshot.png"];

but i guess this method is for UImageViews. How can i do the same thing for a button?
Thank you very much for reading my post :D

Answer Source

One solution to do this would be to display the image in a UIImageView and put a transparent UIButton on top of the UIImageView. In Interface Builder you can change a UIButton to "custom". This would allow you to change the image displayed in the UIImageView easily when handling the action triggered when the UIButton is pushed.

Hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download