详解ios中scrollView上使用masonry

2025-05-29 0 94

使用scrollView的一个子视图对contentSize进行调整

?

1

2

3

4

5
_scroll_Bg = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 100, SCREEN_W, 200)];

_scroll_Bg.pagingEnabled = YES;

_scroll_Bg.delegate = self;

_scroll_Bg.backgroundColor = [UIColor redColor];

[self.view addSubview:_scroll_Bg];

1,现在scrollView添加一个主要子视图,大小贴合scrollView

?

1

2

3

4

5

6

7
UIView *bgView = [[UIView alloc] init];

bgView.backgroundColor = [UIColor blueColor];

[_scroll_Bg addSubview:bgView];

[bgView mas_makeConstraints:^(MASConstraintMaker *make) {

make.top.left.bottom.and.right.equalTo(_scroll_Bg).with.insets(UIEdgeInsetsZero);

make.width.equalTo(_scroll_Bg);

}];

2,此后所有子视图都需添加在此bgView上

?

1

2

3

4

5

6

7

8
UIView *childV = [[UIView alloc] init];

childV.backgroundColor = [UIColor cyanColor];

[bgView addSubview:childV];

[childV mas_makeConstraints:^(MASConstraintMaker *make) {

make.left.right.mas_equalTo(0);

make.top.mas_equalTo(250);

make.height.mas_equalTo(1000);

}];

3,以最后所加子视图为准,再对bgView进行重新约束

?

1

2

3
[bgView mas_makeConstraints:^(MASConstraintMaker *make) {

make.bottom.equalTo(childV.mas_bottom);

}];

以上就是本次给大家整理的全部内容,如果还有任何不明白的地方可以在下方的留言区讨论,感谢你对快网idc的支持。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 详解ios中scrollView上使用masonry https://www.kuaiidc.com/89946.html

相关文章

发表评论
暂无评论