(1) background image, title, image (foreground image) have z-index, which has been set when the UIButton is created, so the effects of setBackgroundImage and setImage are different. (2) Regarding the Image and title in UIButton, Apple’s official documentation explains it in detail: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/ doc/uid/TP40006815-CH3-SW31 (2.1) "Figure 1Providing a title and image for a button" The Content section above explains that title and image are UILabel and UIImageView respectively (2.2) "Configuring Edge Insets" There are three properties in it contentEdgeInsets, titleEdgeInsets, imageEdgeInsets, adjust the values to achieve left text and right image. (2.3) UIImageView also provides detailed instructions on how to resize using resizableImageWithCapInsets:resizingMode:: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/index.html#// apple_ref/occ/cl/UIImageView (2.4) The content display mode of the image is determined by the contentMode of UIImageView; Obviously the background image uses the default mode UIViewContentModeScaleToFill. Please refer to the example: http://blog.csdn.net/iunion/article/details/7494511
Please refer to the following code and modify the contentMode before setImage to see what the difference will be:
(3) It is best to process the picture to a suitable small size in advance, without the confusion you are encountering now. If you use large images now, you have to write a bunch of code for image cropping. Here is a link to UIImage category for your reference: http://blog.sina.com.cn/s/blog_6123f9650100p88p.html
(1) background image, title, image (foreground image) have z-index, which has been set when the UIButton is created, so the effects of setBackgroundImage and setImage are different.
(2) Regarding the Image and title in UIButton, Apple’s official documentation explains it in detail:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIButton_Class/#//apple_ref/ doc/uid/TP40006815-CH3-SW31
(2.1) "Figure 1Providing a title and image for a button" The Content section above explains that title and image are UILabel and UIImageView respectively
(2.2) "Configuring Edge Insets" There are three properties in it contentEdgeInsets, titleEdgeInsets, imageEdgeInsets, adjust the values to achieve left text and right image.
(2.3) UIImageView also provides detailed instructions on how to resize using resizableImageWithCapInsets:resizingMode::
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIImageView_Class/index.html#// apple_ref/occ/cl/UIImageView
(2.4) The content display mode of the image is determined by the contentMode of UIImageView;
Obviously the background image uses the default mode UIViewContentModeScaleToFill.
Please refer to the example:
http://blog.csdn.net/iunion/article/details/7494511
Please refer to the following code and modify the contentMode before setImage to see what the difference will be:
(3) It is best to process the picture to a suitable small size in advance, without the confusion you are encountering now. If you use large images now, you have to write a bunch of code for image cropping. Here is a link to UIImage category for your reference:
http://blog.sina.com.cn/s/blog_6123f9650100p88p.html