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);
}];