UIScrollView 3页滑屏

需要使用UIScrollView实现3页滑屏
得纯代码实现 使用了Masonry适配

需要注意的是
scrollView与3页视图之间还需要一个View

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIScrollView *scrollView = UIScrollView.new;
    
    scrollView.backgroundColor = [UIColor redColor];
    
    [self.view addSubview:scrollView];
    
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    UIView *contentView = UIView.new;
    contentView.backgroundColor = [UIColor blackColor];
    
    [scrollView addSubview:contentView];
    
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.height.equalTo(scrollView);
    }];
    
    UIView *view1 = UIView.new;
    view1.backgroundColor = [UIColor greenColor];
    [contentView addSubview:view1];
    
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0.0);
        make.left.equalTo(@0.0);
        make.width.equalTo(scrollView.mas_width);
        make.height.equalTo(scrollView.mas_height);
    }];
    
    
    UIView *view2 = UIView.new;
    view2.backgroundColor = [UIColor yellowColor];
    [contentView addSubview:view2];
    
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0.0);
        make.left.equalTo(view1.mas_right);
        make.width.equalTo(scrollView.mas_width);
        make.height.equalTo(scrollView.mas_height);
    }];
    
    
    UIView *view3 = UIView.new;
    view3.backgroundColor = [UIColor purpleColor];
    [contentView addSubview:view3];
    
    [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@0.0);
        make.left.equalTo(view2.mas_right);
        make.width.equalTo(scrollView.mas_width);
        make.height.equalTo(scrollView.mas_height);
    }];
    
    [contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(view3.mas_right);
    }];
}
Jietu20190610-110744.jpg
Jietu20190610-110712.jpg
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容