iOS---设置控件的内容模式
2024-09-02 13:48:42
容易混淆的内容摆放属性:
1. textAligment : 文字的水平方向的对齐方式
取值
- NSTextAlignmentLeft = 0, // 左对齐
- NSTextAlignmentCenter = 1, // 居中对齐
- NSTextAlignmentRight = 2, // 右对齐
哪些控件有这个属性 :一般能够显示文字的控件都有这个属性
- UITextField
- UILabel
- UITextView
2. contentVerticalAlignment : 内容的垂直方向的对齐方式
取值
- UIControlContentVerticalAlignmentCenter = 0, // 居中对齐
- UIControlContentVerticalAlignmentTop = 1, // 顶部对齐
- UIControlContentVerticalAlignmentBottom = 2, // 底部对齐
哪些控件有这个属性 : 继承自UIControl的控件或者UIControl本身
- UIControl
- UIButton
- UITextField
3. contentHorizontalAlignment : 内容的水平方向的对齐方式
取值
- UIControlContentHorizontalAlignmentCenter = 0, // 居中对齐
- UIControlContentHorizontalAlignmentLeft = 1, // 左对齐
- UIControlContentHorizontalAlignmentRight = 2, // 右对齐
哪些控件有这个属性 : 继承自UIControl的控件或者UIControl本身
- UIControl
- UIButton
- UITextField
4. contentMode : 内容模式(控制内容的对齐方式), 一般对UIImageView很有用
- 取值
/**
规律:
1.Scale : 图片会拉伸
2.Aspect : 图片会保持原来的宽高比
*/
// 前3个情况, 图片都会拉伸
// (默认)拉伸图片至填充整个UIImageView(图片的显示尺寸会跟UIImageView的尺寸一样)
UIViewContentModeScaleToFill,
// 按照图片原来的宽高比进行伸缩, 伸缩至适应整个UIImageView(图片的内容不能超出UIImageView的尺寸范围)
UIViewContentModeScaleAspectFit,
// 按照图片原来的宽高比进行伸缩, 伸缩至 图片的宽度和UIImageView的宽度一样 或者 图片的高度和UIImageView的高度一样
UIViewContentModeScaleAspectFill,
// 后面的所有情况, 都会按照图片的原来尺寸显示, 不会进行拉伸
UIViewContentModeRedraw, // 当控件的尺寸改变了, 就会重绘一次(重新调用setNeedsDisplay, 调用drawRect:)
UIViewContentModeCenter,
UIViewContentModeTop,
UIViewContentModeBottom,
UIViewContentModeLeft,
UIViewContentModeRight,
UIViewContentModeTopLeft,
UIViewContentModeTopRight,
UIViewContentModeBottomLeft,
UIViewContentModeBottomRight,
- 哪些控件有这个属性 : 所有UI控件都有
5. 如果有多个属性的作用冲突了, 只有1个属性有效(就近原则)
最新文章
- C#学习系列-类与结构的区别
- 2016/12/14---- C3P0
- boost 编译
- 遍历form表单
- Open judge 06月度开销
- C# 获取网页数据、获取本机IP 分类: C# 2014-12-16 14:59 308人阅读 评论(0) 收藏
- linux dd命令参数及用法详解---用指定大小的块拷贝一个文件(也可整盘备份)
- Largest Submatrix(动态规划)
- jQeury学习笔记
- React native android 最常见的10个问题
- java 文件字节输出流
- aProxy: 带认证授权和权限控制的反向代理
- sql优化原则与技巧
- Flask开发基础
- python干掉pycache
- Mysql分页优化
- 解决 git push Failed to connect to 127.0.0.1 port 8-87: 拒绝连接
- springcloud-3:required a bean of type 'com.netflix.discovery.DiscoveryClient' that could not be found.
- ajax-简单参数方法实现阴影效果
- 解决jmeter乱码
热门文章
- 强连通分量+poj2186
- C++ 函数部分(1)
- python iterable 和list、dictionary的区别和联系
- socket.io中文文档
- UVA11183 Teen Girl Squad —— 最小树形图
- 使用Kotlin如何startActivity
- HubbleDotNet开源全文搜索数据库项目--技术详解
- codeforces 689C C. Mike and Chocolate Thieves(二分)
- AutoIT: 学习对GUI Sample上所有的资源进行操作
- python requests 调用restful api