【iOS】Scale Fill、Aspect Fit 和 Aspect Fill 的区别(Content Mode)

ImageView –  Content Mode中Scale FillAspect Fit Aspect Fill 的区别

Scale Fill:缩放(改变图片比例)以填满整个Image View

Aspect Fit:保持图片原比例,尽可能让图片全部显示出来,Image View 剩下空出来的部分是透明的

Aspect Fill:保持图片原比例,填满整个Image View(图片可能会被裁剪掉)

图片示例(只好牺牲这只可爱的小喵咪啦~):

Scale Fill

 Aspect Fit

Aspect Fill


UIViewContentModeScaleToFillScales the content to fit the size of itself by changing the aspect ratio of the content if necessary.

UIViewContentModeScaleAspectFitScales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.

UIViewContentModeScaleAspectFillScales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.

❤ 点击这里 -> 订阅《PAT | 蓝桥 | LeetCode学习路径 & 刷题经验》by 柳婼

❤ 点击这里 -> 订阅《从放弃C语言到使用C++刷算法的简明教程》by 柳婼

❤ 点击这里 -> 订阅PAT甲级乙级、蓝桥杯、GPLT天梯赛、LeetCode题解离线版