UIButton won't go to Aspect Fit in iPhone

The solution is to set the contentMode on the imageView property of the UIButton. The UIButton has to be created with custom type for this to work I believe (otherwise nil is returned for this property).


This method worked for me very well.:

In Xib select the button and set user defined runtime attributes:

  • Key path: self.imageView.contentMode
  • Type: Number
  • Value: 1

Click here to see more clearly the solution

We use number because you cant use enum there. But the UIViewContentModeScaleAspectFit is equal to 1.


I've had that problem before. I solved it by putting my image in a UIImageView, where contentMode settings actually work, and putting a transparent custom UIButton over top of that.

EDIT: This answer is obsolete. See @Werner Altewischer's answer for the correct answer in modern versions of iOS.