UI美化
1.1Button的可点击范围内限制button内的图片大小
很多时候我们为了美化界面需要将button的背景图片更改,但是又要兼顾到button的大小和图片的大小是否影响美观;
那么我们就需要用到这个方法:
button.imageEdgeInsets = UIEdgeInsetsMake(top: CGFloat,left: CGFloat, bottom: CGFloa,right: CGFloat)
效果展示:
storyBoard中button大小,即可点击范围(宽高36*58):
实际button显示背景大小(以button的x=0,y=0为图片中心);(宽高8*19)
1.1.1源码
self.button.setImage(UIImage(named: String), forState: .Normal) self.button.imageEdgeInsets = UIEdgeInsetsMake(top: CGFloat,left: CGFloat, bottom: CGFloa,right: CGFloat)