iOS UIView contentMode

简介:

Content Modes

contentMode是UIView的属性,这个属性的值决定了,当视图的几何形状变化时如何复用它的内容。当视图第一次展示前,它会将自己的内容渲染成一张底层的bitmap. 然后视图的几何变化都不会使bitmap重新生成。而视图contentMode属性的值决定了bitmap是否缩放、位置在哪儿(固定在左边、右边、上面、下面、居中)。默认情况下,contentMode的值是UIViewContentModeScaleToFill。

contentMode啥时候起作用呢?

  • 视图frame或bounds的高宽发生变化
  • 赋给 view的transform属性的值带有scale
UIViewContentModeScaleToFill

Scales the content to fit the size of itself by changing the aspect ratio of the content if necessary.
 改变内容的高宽比例,缩放内容,UIView中完整显示内容,填满UIView,

UIViewContentModeScaleAspectFit
 Scales the content to fit the size of the view by maintaining the aspect ratio. Any remaining area of the view’s bounds is transparent.
保持内容的高宽比,缩放内容,完整显示内容,最大化填充UIview,没填充上的区域透明


UIViewContentModeScaleAspectFill
Scales the content to fill the size of the view. Some portion of the content may be clipped to fill the view’s bounds.
保持内容高宽比,缩放内容,超出视图的部分内容会被裁减,填充UIView
需要把View的 clipsToBounds 设置为YES;

UIViewContentModeRedraw
The option to redisplay the view when the bounds change by invoking the setNeedsDisplay method.
当View的bounds改变,系统会调用setNeedsDisplay,重新绘制视图


UIViewContentModeCenter
The option to center the content in the view’s bounds, keeping the proportions the same.
不缩放,内容在视图中间


UIViewContentModeTop
The option to center the content aligned at the top in the view’s bounds.


UIViewContentModeBottom
The option to center the content aligned at the bottom in the view’s bounds.


UIViewContentModeLeft
The option to align the content on the left of the view.


UIViewContentModeRight
The option to align the content on the right of the view.


UIViewContentModeTopLeft
The option to align the content in the top-left corner of the view.


UIViewContentModeTopRight
The option to align the content in the top-right corner of the view.


UIViewContentModeBottomLeft
The option to align the content in the bottom-left corner of the view.


UIViewContentModeBottomRight
The option to align the content in the bottom-right corner of the view.
AI 代码解读

效果图:


image

参考链接stackoverflow

Content Modes



目录
打赏
0
0
0
0
10
分享
相关文章
iOS 内容对齐 TextAlignment & VerticalAlignment & HorizontalAlignment & contentMode
iOS 内容对齐 TextAlignment & VerticalAlignment & HorizontalAlignment & contentMode
161 0
iOS开发之指定UIView的某几个角(小于4)为圆角
在iOS开发中,我们经常会遇到View设置圆角的问题,如果需要将UIView的4个角全部都为圆角,做法相当简单,只需设置其Layer的cornerRadius属性即可(项目需要使用QuartzCore框架)。而若要指定某几个角(小于4)为圆角而别的不变时,这种方法就不好用了。
iOS开发之指定UIView的某几个角(小于4)为圆角
iOS动画开发之三——UIView的转场切换
iOS动画开发之三——UIView的转场切换
417 0
iOS动画开发之二——UIView动画执行的另一种方式
iOS动画开发之二——UIView动画执行的另一种方式
135 0
iOS开发之UIView与UIViewController的生命周期总结
iOS开发中,创建View常见的两种方式一个是纯代码,一个是借助于XIB;创建ViewController常见的也有两种方式一个是纯代码,一个是借助于StoryBoard。
1291 0
iOS 开发之指定 UIView 的某几个角为圆角
如果需要将 UIView 的 4 个角全部都为圆角,做法相当简单,只需设置其 Layer的 cornerRadius 属性即可(项目需要使用QuartzCore框架)。
2028 0

热门文章

最新文章

  • 1
    苹果app上架-ios上架苹果商店app store 之苹果支付In - App Purchase内购配置-优雅草卓伊凡
    63
  • 2
    苹果app上架app store 之苹果开发者账户在mac电脑上如何使用钥匙串访问-发行-APP发布证书ios_distribution.cer-优雅草卓伊凡
    48
  • 3
    uniapp云打包ios应用证书的获取方法,生成指南
    56
  • 4
    iOS|解决 setBrightness 调节屏幕亮度不生效的问题
    127
  • 5
    iOS|记一名 iOS 开发新手的前两次 App 审核经历
    30
  • 6
    iOS各个证书生成细节
    45
  • 7
    【01】噩梦终结flutter配安卓android鸿蒙harmonyOS 以及next调试环境配鸿蒙和ios真机调试环境-flutter项目安卓环境配置-gradle-agp-ndkVersion模拟器运行真机测试环境-本地环境搭建-如何快速搭建android本地运行环境-优雅草卓伊凡-很多人在这步就被难倒了
    227
  • 8
    Cellebrite UFED 4PC 7.71 (Windows) - Android 和 iOS 移动设备取证软件
    72
  • 9
    【03】仿站技术之python技术,看完学会再也不用去购买收费工具了-修改整体页面做好安卓下载发给客户-并且开始提交网站公安备案-作为APP下载落地页文娱产品一定要备案-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    87
  • 10
    【02】仿站技术之python技术,看完学会再也不用去购买收费工具了-本次找了小影-感觉页面很好看-本次是爬取vue需要用到Puppeteer库用node.js扒一个app下载落地页-包括安卓android下载(简单)-ios苹果plist下载(稍微麻烦一丢丢)-优雅草卓伊凡
    72