首页 > 其他 > 详细

Masonry

时间:2015-11-30 20:16:29      阅读:197      评论:0      收藏:0      [点我收藏+]
- (void)viewDidLoad {
    [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];
    
    UIView * greenView = [[UIView alloc]init];
    greenView.backgroundColor = [UIColor greenColor];
    [self.view addSubview:greenView];
    
    self.redView = redView;
    self.blueView = blueView;
    self.greenView = greenView;

    [self.redView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.bottom.equalTo(self.view);
        make.height.equalTo(@80);
        make.width.equalTo(self.blueView);
        make.width.equalTo(self.greenView);
        make.right.equalTo(self.blueView.mas_left);
    }];
    
    [self.blueView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.and.width.and.height.equalTo(self.redView);
        make.left.equalTo(self.redView.mas_right);
        make.right.equalTo(self.greenView.mas_left);
    }];
    
    [self.greenView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.and.width.and.height.equalTo(self.redView);
        make.left.equalTo(self.blueView.mas_right);
        make.right.equalTo(self.view);
    }];
}

UILabel * testLabel = [[UILabel alloc]init];
    testLabel.backgroundColor = [UIColor lightGrayColor];
    testLabel.text = @"我要好好学习";
    [self.view addSubview:testLabel];
    [testLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view);
        make.bottom.equalTo(self.redView.mas_top);
    }];//不设置宽和高也可以

  

  就不用写viewWillapear了

Masonry

原文:http://www.cnblogs.com/tanglimei/p/5007757.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!