iOS -- autoResizingMask使用(转)
autoResizingMask 是UIView的一个属性,在一些简单的布局中,使用autoResizingMask,可以实现子控件相对于父控件的自动布局。
autoResizingMask 是UIViewAutoresizing 类型的,其定义为:
@property(nonatomic) UIViewAutoresizing autoresizingMask; // simple resize. default is UIViewAutoresizingNone
UIViewAutoresizing 是一个枚举类型,默认是 UIViewAutoresizingNone,其可以取得值有:
typedef NS_OPTIONS(NSUInteger, UIViewAutoresizing) {
UIViewAutoresizingNone = ,
UIViewAutoresizingFlexibleLeftMargin = << ,
UIViewAutoresizingFlexibleWidth = << ,
UIViewAutoresizingFlexibleRightMargin = << ,
UIViewAutoresizingFlexibleTopMargin = << ,
UIViewAutoresizingFlexibleHeight = << ,
UIViewAutoresizingFlexibleBottomMargin = <<
};
各属性解释:
UIViewAutoresizingNone |
不会随父视图的改变而改变 |
UIViewAutoresizingFlexibleLeftMargin |
自动调整view与父视图左边距,以保证右边距不变 |
UIViewAutoresizingFlexibleWidth |
自动调整view的宽度,保证左边距和右边距不变 |
UIViewAutoresizingFlexibleRightMargin |
自动调整view与父视图右边距,以保证左边距不变 |
UIViewAutoresizingFlexibleTopMargin |
自动调整view与父视图上边距,以保证下边距不变 |
UIViewAutoresizingFlexibleHeight |
自动调整view的高度,以保证上边距和下边距不变 |
UIViewAutoresizingFlexibleBottomMargin |
自动调整view与父视图的下边距,以保证上边距不变 |
注意:autoResizingMask 既可以在代码中直接使用,也可以在UIStoryboard中使用。
一个代码中使用autoResizingMask的例子:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UIViewController *viewController = [[UIViewController alloc] init];
self.window.rootViewController = viewController;
self.window.backgroundColor = [UIColor whiteColor]; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(,,,)];
[view setBackgroundColor:[UIColor grayColor]];
[self.window addSubview:view]; UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(,,,)];
[button setBackgroundColor:[UIColor whiteColor]];
[view addSubview:button];
//距离父视图右边距不变
//button.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
//距离父视图的左边距不变
//button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin;
//距离父视图的左右边距不变,button大小会调整
//button.autoresizingMask = UIViewAutoresizingFlexibleWidth;
//view.frame = CGRectMake(20,100,300,100); //距离父视图的下边距不变
//button.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
//距离父视图的上边距不变
//button.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin;
//距离父视图的上下边距不变,button大小会调整
button.autoresizingMask = UIViewAutoresizingFlexibleHeight;
view.frame = CGRectMake(,,,); [self.window makeKeyAndVisible];
return YES;
}
另外,autoResizingMask 可以组合使用。例如:
button.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin;
表示的是,子控件相对于父控件的顶部和右侧的距离不变。
iOS -- autoResizingMask使用(转)的更多相关文章
- IOS - autoresizingMask
提醒:当frame设定死,慎用autoresizingMask:否则该frame变形的难以想象.
- IOS - 控件的AutoresizingMask属性
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. enum { UIViewAutoresi ...
- ios的AutoresizingMask【转】
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. enum { UIViewAutoresi ...
- iOS开发-自动布局之autoresizingMask使用详解(Storyboard&;Code)
前言:现在已经不像以前那样只有一个尺寸,现在最少的IPHONE开发需要最少需要适配三个尺寸.因此以前我们可以使用硬坐标去设定各个控件的位置,但是现在的话已经不可以了,我们需要去做适配,也许你说可以使用 ...
- ios 中的autoresizingMask
以前对这个知识理解的不太对,看了下面这个地址的文章后,感觉说的对,也没检验,今天实验后,发现是错的...在这里对以前读过此文的朋友表示抱歉. 原文地址如下: http://www.cnblogs.co ...
- iOS开发 autoResizingMask使用
autoResizingMask 是UIView的一个属性,在一些简单的布局中,使用autoResizingMask,可以实现子控件相对于父控件的自动布局. autoResizingMask 是UIV ...
- iOS开发——View的autoresizingMask属性
View的自适应属性autoresizingMask属性 每一个UIView都有一个autoresizingMask属性,这个属性是用于适应父视图的大小与子视图适应的,源码如下 enum { UIVi ...
- 【iOS 】UIView 中有一个autoresizingMask的属性
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. 1 2 3 4 5 6 7 8 9 enum ...
- ios开发之--关于UIView的autoresizingMask属性的研究
在 UIView 中有一个autoresizingMask的属性,它对应的是一个枚举的值(如下),属性的意思就是自动调整子控件与父控件中间的位置,宽高. enum { UIViewAutoresizi ...
随机推荐
- Java 深拷贝、浅拷贝及Cloneable接口
Cloneable接口是一个空接口,仅用于标记对象,Cloneable接口里面是没有clone()方法,的clone()方法是Object类里面的方法!默认实现是一个Native方法 protecte ...
- NSURLSession总结
NSURLSession(会话)(ios7新增加) //英译 Session:会议,讲话 configuration:结构,配置 expect:预期 resume:取得 suspend:推迟 pro ...
- Windows Phone 七、XML序列化
DataContractSerializer对象 public class Person { public int Id { get; set; } public string Name { get; ...
- sqlserver索引与查询优化
此文为转载,仅做保存使用,出处:http://www.cr173.com/html/8688_all.html 在数据库存优化设计中往往会提到索引,这编文章就来详细的说明一下在 SQL SERVER ...
- Ajax与用户交互的存储格式JSON
数据存储是JavaScript的核心功能,这是一个在学习前期的一个容易让人迷惑的问题.它并不是那种像页面滑动.幻灯片展示.淡入淡出等吸引人眼球的特效.适当的存放好数据,就有利于我们组织起结构,又能使应 ...
- mysql 查看 删除 日志操作总结(包括单独和主从mysql)
我们可以在mysql的安装目录下看到mysql的二进制日志文件,如mysql-bin.000***等,很多人都不及时的处理,导致整个硬盘被塞满也是有可能的.这些是数据库的操作日志.它记录了我们平时使用 ...
- shell 下的$符合
$n $1 the first parameter,$2 the second...$# The number of command-line parameters.$0 ...
- wampserver 2.2装好后80端口未被占用,却打不开localhost
在windows server 2003中装好wampserver2.2后打不开localhost,点击服务全部启动(颜色是橙色)也是打不开,我解决的原因是:安装mysql中sevice中的安装测试服 ...
- 笔记:Spring Cloud Ribbon RestTemplate 详解
详细介绍RestTemplate 针对几种不同请求类型和参数类型的服务调用实现,示例代码中的 restTemplate 都是通过Spring 注入方式创建的,相关代码如下: @Autowired pr ...
- leetcode — minimum-window-substring
import java.util.HashMap; import java.util.Map; /** * * Source : https://oj.leetcode.com/problems/mi ...