在开发中,经常会使用到图片,我们给一个ImageView设置了固定的大小,但是得到的图片往往不是这个大小,造成图片被拉伸或压缩变形,你要合理利用这几个属性,就可以得到很多想要的效果了
searchIcon.contentMode
typedef NS_ENUM(NSInteger, UIViewContentMode) {
UIViewContentModeScaleToFill, // 根据UIImageView的大小,占据整个,会出现拉伸和压缩
UIViewContentModeScaleAspectFit, // contents scaled to fit with fixed aspect. remainder is transparent 根据UIImageView的大小,将图片等比缩小到能放下
UIViewContentModeScaleAspectFill, // contents scaled to fill with fixed aspect. some portion of content may be clipped. 搭配maskToBounds = YES; 就可以从中间裁切出完美的图片了
UIViewContentModeRedraw, // redraw on bounds change (calls -setNeedsDisplay)
UIViewContentModeCenter, // contents remain same size. 尺寸一样,放在中间部分positioned adjusted.
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
};
图片在UIImageView上呈现的效果
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
相关阅读更多精彩内容
- UIImageView的ContentMode的这些参数,这些参数一般就能满分我们的开发需求 UIViewCont...
- UIImageView的contentMode这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,系统给出...
- UIImageView 的contentMode这个属性是用来设置图片的显示方式,如居中、居右,是否缩放等,有以下...
- 一.常用属性 1、image: default is nil。图片属性 image的格式可以是.png或者.jpg...