iosiphoneuibuttonaspect-fit

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.


Solution

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