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 inspectorimageView.contentMode, where you set value relatively to rawValue position of enum UIViewContentMode. 1 means scaleAspectFit.

Set button.imageView.contentMode in Storyboard

And button's alignment, in Attributes inspector:

Full alignment of button


In Swift...

button.imageView?.contentMode = . scaleAspectFit

Have you tried setImage instead of setBackgroundImage?