美文网首页iOS UI
UIScrollView使用Masonry布局

UIScrollView使用Masonry布局

作者: 飞天蛤蟆 | 来源:发表于2017-04-23 17:26 被阅读0次

    1, 首先创建UIScrollView,
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
    [self.view addSubview:scrollView];
    2, 创建bgView
    UIView *bgView = [[UIView alloc]init];
    [scrollView addSubview:bgView];
    这个view是用来放置子控件的
    3, 创建子控件, 添加到bgView上面
    UILabel *label = [[UILabel alloc]init];
    label.text = @"标题";
    [bgView addSubview:label];

    UIView *headView = [[UIView alloc]init];
    headView.backgroundColor = [UIColor greenColor];
    [bgView addSubview:headView];
    
    UIView *bottomView = [[UIView alloc]init];
    bottomView.backgroundColor = [UIColor redColor];
    [bgView addSubview:bottomView];
    
    UIView *view1 = [[UIView alloc]init];
    view1.backgroundColor = [UIColor blueColor];
    [bgView addSubview:view1];
    

    4,设置bgView的约束
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(scrollView);
    make.width.equalTo(scrollView);
    }];
    [headView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.equalTo(label);
    make.top.equalTo(label.mas_bottom).offset(20);
    make.height.mas_equalTo(80);
    }];
    [bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.equalTo(headView);
    make.top.equalTo(headView.mas_bottom).offset(20);
    make.height.mas_equalTo(900);
    }];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.equalTo(bgView);
    make.top.equalTo(bottomView.mas_bottom).offset(30);
    make.height.mas_equalTo(80);
    make.bottom.equalTo(bgView);
    }];

    相关文章

      网友评论

        本文标题:UIScrollView使用Masonry布局

        本文链接:https://www.haomeiwen.com/subject/ndeyzttx.html