Thursday, May 26, 2011

Setting Image on UIButton

Hello Friends,

Today we will throw a light on very common topic. We often required to set image on UIButton. Images can be set on UIButton with 2 methods. We can set image as button image and button background image.


Generally, We do not set image in button as image inside button because if we set button image then UIButton will enlarge according to the image size. So I prefer you to set Image on background so image will fit to button size.

To set Button title:
[btnImg setTitle:@"ABC" forState: UIControlStateNormal];

To set Background Image in button:
[btnImg setBackgroundImage:image forState: UIControlStateNormal];

To set Button Image:
[btnImg setImage:image forState: UIControlStateNormal];

Have a nice day..!!!

No comments:

Post a Comment