UIButton won't go to Aspect Fit in iPhone

后端 未结 21 1979
小鲜肉
小鲜肉 2020-12-23 02:47

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 d

21条回答
  •  生来不讨喜
    2020-12-23 03:30

    This overlaps many of the other answers, but the solution for me was to

    • set the contentMode of the UIImageView for the button to .ScaleAspectFit – which can either be done in the ”User Defined Runtime Attributes” in Interface Builder (ie. self.imageView.contentMode, Number, 1) or in a UIButton subclass;
    • disable ”Autoresize Subviews”;
    • set ”Edge” to ”Image” and appropriate ”Top” and ”Bottom” values for ”Inset” (which might only be needed if you, like me, used a PDF as image).

提交回复
热议问题