Why does a custom UIButton image does not resize in Interface Builder?

前端 未结 10 1175
你的背包
你的背包 2020-12-24 00:45

Why does a custom UIButton image not resize with the button?

I set its view mode to Scale to Fill in Interface Builder, but unlike a UIImageView image, it d

10条回答
  •  天涯浪人
    2020-12-24 01:30

    The best solution I found so far in Swift 2.1 is the following:

    self.imageButton.imageView?.clipsToBounds = true
    self.imageButton.imageView?.contentMode = UIViewContentMode.ScaleAspectFit
    

    This will scale the image so it has an aspect fit in the imageView.

提交回复
热议问题