Why does a custom UIButton image does not resize i

2019-02-01 10:03发布

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 doesn't respect that setting.

Am I looking in the wrong place or is it not possible?

9条回答
迷人小祖宗
2楼-- · 2019-02-01 10:28

Remember to set Control Alignment settings for the button

here set Control Alignment settings for the button

查看更多
看我几分像从前
3楼-- · 2019-02-01 10:29

Try setting the Clip subviews property in Interface Builder to true.

Hope that helps.

查看更多
▲ chillily
4楼-- · 2019-02-01 10:38

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.

查看更多
登录 后发表回答