在某些情况下,我们使用的UIButton的背景图片不一定就是标准的尺寸,有时会偏大,那么怎么办?
这个比较简单直接设置 : self.imageView.contentMode = UIViewContentModeScaleAspectFill;
但是问题来了,如果图片尺寸比较button的bounds 小的话,他不会撑满整个控件默认会居中显示,有些时候这并不是我们想要的效果。有时我们希望他能撑满整个button。
1 | - (CGRect)imageRectForContentRect:(CGRect)bounds{ |
2 | return CGRectMake(0.0, 0.0, self.size.width, self.size.height); |
3 | } |