开发者

What's the difference between setBackgroundImage:Forstate and setImage:Forstate:

I am trying to set a image for a UIButton.

I don't kn开发者_如何学Pythonow the difference between the setBackgroundImage:Forstate and setImage:Forstate:

Could anyone help me out?

Thanks and best regards.


  1. setImage:forState: sets the image as the actual content of the button. For example, you can not see the button title even though you set it, because you have set an image as the content.

  2. setBackgroundImage:forState: sets the image as the background. In this case, you can set the title and it is displayed on top of the image.


setBackgroundImage: follows the frame, i.e. if u change the frame, the background image is streched or shrinked with it. Contrary on the setImage, its not the same. The image takes its own size. In setImage the image is the actual content of the button.


The difference is in the framing

I will explain you with the help of example suppose your image size is 40*40 and button frame is 20*20 then if you use setBackgroundImage:forState: method the image will be displayed in 20*20 frame and if you use setImage:forState: method you will see a button with image size of 40*40 frame. This is the difference.

Happy Coding!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜