美文网首页
UIScrollView使用Masonry布局

UIScrollView使用Masonry布局

作者: 滴滴滴开门 | 来源:发表于2024-06-26 09:56 被阅读0次

// 1, 首先创建UIScrollView,
UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:self.view.bounds];
if (@available(iOS 11.0, *)) {
UIScrollView.appearance.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
// 2, 创建bgView
UIView *bgView = [[UIView alloc]init];

UIView *headView = [[UIView alloc]init];
headView.backgroundColor = [UIColor greenColor];

UIView *bottomView = [[UIView alloc]init];
bottomView.backgroundColor = [UIColor redColor];



[self.view addSubview:scrollView];
[scrollView addSubview:bgView];
[bgView addSubview:headView];
[bgView addSubview:bottomView];

// 4,设置bgView的约束

[scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(self.view).mas_offset(UIDevice.vg_statusBarHeight);
    make.left.right.bottom.mas_equalTo(self.view);
}];

[bgView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.edges.equalTo(scrollView);
    make.width.equalTo(scrollView);
}];

[headView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.left.right.equalTo(bgView);
    make.top.equalTo(bgView).offset(0);
    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);
    make.bottom.equalTo(bgView);
}];

相关文章

网友评论

      本文标题:UIScrollView使用Masonry布局

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