Please tell me what's the difference between two UIButton methods:
- (void)setBackgroundImage:(UIImage *)image forState:(UIControlState)state
and
- (void)setImage:(UIImage *)image forState:(UIControlState)state
Apple documentation says nothing about it.
UIImage contains the data for an image. UIImageView is a custom view meant to display the UIImage . Save this answer.
A control that executes your custom code in response to user interactions.
An object that manages image data in your app.
To create constraints select the button and click the Align icon in the auto layout menu. A popover menu will appear, check both “Horizontal in container” and “Vertically in container” options to center the button on the screen.
setBackgroundImage
sets the background image of the button. Typically you use this in conjunction with a button of type "Custom" to use the background image as a nice shape and background for the button (say an image representing a rectangle with rounded corners and filled with a nice gradient)
setImage
adds an image/icon next to the title of the button, (all of which, image and title, are overlayed over the background image, of course, that's why it's called "background" after all). If you set some title to you button too, the image will be drawn next to the title and its position will depend on the title length (and also on the titleContentInsets / imageContentInsets properties to adjust this position)
Just try it in Interface Builder (set an image for both, play around by setting a title, etc) you will understand it easier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With