UIButton won't go to Aspect Fit in iPhone

marty picture marty · Aug 11, 2010 · Viewed 67.6k times · Source

I have a couple UIButtons, and in IB they're set to Aspect Fit, but for some reason they're always stretching. Is there something else you have to set? I tried all the different view modes and none of them work, they all stretch.

Answer

Werner Altewischer picture Werner Altewischer · Oct 22, 2010

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).