UIButton won't go to Aspect Fit in iPhone

后端 未结 21 2191
小鲜肉
小鲜肉 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:28

    Similar to @Guillaume, I have created a subclass of UIButton as a Swift-File. Then set my custom class in the Interface Builder:

    .

    And here the Swift file:

    import UIKit
    
    class TRAspectButton : UIButton {
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            self.imageView?.contentMode = .ScaleAspectFit
        }
    }
    

提交回复
热议问题