Masonry 自动布局 cocopods

来源:互联网 发布:软件测试招聘上海 编辑:程序博客网 时间:2024/05/24 06:33

 //首先使用cocopods 下载Masonry 在右cocopods的工程中写下面代码:


#define WEAKSELF(weakSelf) __weak __typeof(&*self)weakSelf = self


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

    view1.backgroundColor = [UIColor redColor];

    [self.view addSubview:view1];

//block 定义的宏

    WEAKSELF(weakSelf);


 [view1mas_makeConstraints:^(MASConstraintMaker *make) {

       // make.left.equalTo(self.view);

        make.left.mas_equalTo(weakSelf.view.mas_left);

        make.size.mas_equalTo(CGSizeMake(200, 100));

    }];

    UIView *view2 = [[UIViewalloc]init];

    view2.backgroundColor = [UIColor greenColor];

    [self.view addSubview:view2];

    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.width.mas_equalTo(@(150));

        make.height.mas_equalTo(view1);

        make.left.mas_equalTo(view1.mas_right).offset(20);

        make.top.mas_equalTo(view1.mas_top);

    }];

    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {

        make.edges.mas_equalTo(weakSelf.view).insets(UIEdgeInsetsMake(10,10, 10, 10));

    }];


0 0
原创粉丝点击