UIImageVIew

ContentMode使用

1. 最常用的 Fill 和 Fit使用

  1. xib创建默认是aspectFit
  2. 代码创建默认是ScaleToFill

(1). 这个保证图片变形, 除非尺寸跟图片一样,根据宽高, 自动填充

UIViewContentModeScaleToFill

(2).这两个是保证图片不变形的

UIViewContentModeScaleAspectFill, // 根据最大一边缩放, 自动填充, 多余剪掉 
UIViewContentModeScaleAspectFit, // 根据最大一边缩放, 不填充

2. 跟上面结合使用

imageView.contentMode = UIViewContentModeScaleAspectFill | UIViewContentModeTop;

UIViewContentModeRedraw // 尺寸改变时重绘
UIViewContentModeCenter。 // 中间
UIViewContentModeTop // 顶部, 图片居中显示
UIViewContentModeBottom // 底部
UIViewContentModeLeft // 中间贴左
UIViewContentModeRight // 中间贴右
UIViewContentModeTopLeft // 贴左上
UIViewContentModeTopRight // 贴右上
UIViewContentModeBottomLeft // 贴左下
UIViewContentModeBottomRight// 贴右下

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容