Autolayout

1.这个位置选适应什么样子的屏幕

2.两种方法选择约束

第一种:

第二种:

3.代码添加约束————导入第三方库Masnory

 [super viewDidLoad];

    UIView * redview = [[UIView alloc]init];

    redview.backgroundColor = [UIColor redColor];

    [self.view addSubview:redview];

    UIView * blueview = [[UIView alloc]init];

    blueview.backgroundColor = [UIColor blueColor];

    [self.view addSubview:blueview];

  

    [redview mas_makeConstraints:^(MASConstraintMaker *make) {

        make.leading.equalTo(self.view.mas_leading).offset(10);

        make.top.equalTo(self.view.mas_top).offset(10);

        make.height.equalTo(@100);

    }];

    [blueview mas_makeConstraints:^(MASConstraintMaker *make) {

        make.trailing.equalTo(self.view.mas_trailing).offset(-10);

        make.top.equalTo(self.view.mas_top).offset(10);

        make.height.equalTo(redview.mas_height).offset(0);

        make.width.equalTo(redview.mas_width).offset(0);

        make.leading.equalTo(redview.mas_trailing).offset(10);

    }];

原文地址:https://www.cnblogs.com/huoran1120/p/5133757.html