Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton won't go to Aspect Fit in iPhone

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.

like image 941
marty Avatar asked Aug 11 '10 16:08

marty


2 Answers

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

like image 53
Werner Altewischer Avatar answered Sep 28 '22 01:09

Werner Altewischer


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.

like image 41
István Stefánovics Avatar answered Sep 28 '22 01:09

István Stefánovics