Sabo Sabo - 3 months ago 7
iOS Question

How to change Custom Button's Image when Tapping in iOS?

I used custom button with Image.
In normally , When we tapping button , the color of button has been changed.

When i tapping that custom button , i want to change image from custom button.

How can i change it?

Thanks.

Answer

assuming this is a standard UIButton, you can do the following when initializing the button:

[btnObj setImage:[UIImage imageNamed:@"imgName.png"] forState:UIControlStateHighlighted];

or for the Background image:

[btnObj setBackgroundImage:[UIImage imageNamed:@"imgName.png"] forState:UIControlStateHighlighted];
Comments