iOS UIViewd的Content Modes属性 调整 ImageView 图片自适应模式 展示样式 UIViewContentMode各类型效果

本文详细介绍了UIView的contentMode属性,解释了它如何调整视图层的缓存位图以适应视图边界的变化,这对于实现可缩放的控件特别有用。通过不同的contentMode设置,可以实现图片的缩放、拉伸或固定到视图特定位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

类似于 Label 的 文字居中类型,在展示图片时,也有一个ContentMode 属性 控制 图片展示的居中等样式.
contentMode 是 UIview 的一个属性

官网描述

The content mode specifies how the cached bitmap of the view’s layer is adjusted when the view’s bounds change. This property is often used to implement resizable controls. Instead of redrawing the contents of the view every time, you can use this property to specify that you want to scale the contents (either with or without distortion) or pin them to a particular spot on the view.

这里就不翻译了,
上官网地址

contentMode是什么
https://developer.apple.com/reference/uikit/uiview/1622619-contentmode

contentMode的值
https://developer.apple.com/reference/uikit/uiviewcontentmode

那么各个取值的效果如何呢

同样 上图,来自于官网

展示

上地址

图片官网来源
https://developer.apple.com/library/content/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值