How to not stretch an image in UIButton
Make sure the button is a Custom UIButton
Just using setImage:
did not work for me on iOS9.
But it worked combined with myButton.imageView.contentMode = UIViewContentMode.ScaleAspectFit;
Storyboard
Property image.
You must define specific property in Runtime Attributes of Identity inspector – imageView.contentMode
, where you set value relatively to rawValue
position of enum UIViewContentMode
. 1 means scaleAspectFit.
And button's alignment, in Attributes inspector:
In Swift...
button.imageView?.contentMode = . scaleAspectFit
Have you tried setImage
instead of setBackgroundImage
?