UIViewAutoresizingNone 就是不自动调整。
UIViewAutoresizingFlexibleLeftMargin 距离父控件的左边是可以拉伸的,保证与superView右边的距离不变。
UIViewAutoresizingFlexibleRightMargin 距离父控件的右边是可以拉伸的,保证与superView左边的距离不变。
UIViewAutoresizingFlexibleTopMargin 距离父控件的顶部是可以拉伸的,保证与superView底部的距离不变。
UIViewAutoresizingFlexibleBottomMargin 距离父控件的底部是可以拉伸的,与superView顶部的距离不变。
UIViewAutoresizingFlexibleWidth 宽度会跟随父控件的宽度进行拉伸
UIViewAutoresizingFlexibleHeight 高度会跟随父控件的高度进行拉伸
前端的主要任务简单来看,就是绘制界面,绑定数据。在iOS绘制界面的布局方式主要有以下三种:
frame
autoresizingMask
AutoLayout
fame:常用于绝对布局,通过设置x, y, width, height来确定控件的位置和大小。
autoresingMask:苹果早期的相对布局的方案,允许子视图跟随父视图变化而变化,比如按比例缩放宽高,按比例缩放边距,仅限于两个视图之间使用,需要fame配合使用[不建议代码使用,可以在xib中使用]。
AutoLayout:iOS6引入基于关系的相对布局方式,允许视图与另外一个或者多个视图保持约束关系,可以在多个视图间使用,但是建议参考父视图添加约束,系统可以自动将frame转为约束。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIView *redView = [[UIView alloc] init];
redView.backgroundColor = [UIColor redColor];
CGFloat marginX = self.view.frame.size.width - 100;
CGFloat marginY = self.view.frame.size.height - 100;
redView.frame = CGRectMake(marginX, marginY, 100, 100);
[self.view addSubview:redView];
redView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
}
@end