ios uiscrollview 使用Masonry布局,不起作用问题

1 .使用Masonry 布局 , 需要在scrollview上加一个空白view 用来布局

2. 使用scrollview 滚动 

3. 代码 :

UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.showsVerticalScrollIndicator = YES;
    [self.view addSubview:scrollView];
    [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.top.equalTo(self.view);
    }];
    
    self.contentView = [[UIView alloc] init];
    self.contentView.backgroundColor = [UIColor whiteColor];
    [scrollView addSubview:self.contentView];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.mas_equalTo(kSCREEN_W);
    }];
    for (int i = 0; i < 40; i++) {
        self.detailLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 100 + i*60, self.view.bounds.size.width, 50)];
        self.detailLb.text = @"小北青年";
        self.detailLb.textColor = [UIColor redColor];
        [self.contentView addSubview:self.detailLb];
    }
       UILabel *detailLb8 = [[UILabel alloc] init];
       detailLb8.text = @"小北青年";
       detailLb8.textColor = [UIColor redColor];
       [self.contentView addSubview:detailLb8];
    [detailLb8 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.detailLb.mas_bottom).offset(30);
        make.width.mas_equalTo(kSCREEN_W);
        make.height.mas_equalTo(40);
        make.bottom.mas_equalTo(self.contentView.mas_bottom).offset(60);
    }];

你可能感兴趣的:(ios进阶)