Masonry布局之UIScrollview

(一)话不多说,直接上代码;

#import "ScrollerViewController.h"

@interface ScrollerViewController ()

@property (nonatomic,strong) UIScrollView *scroller;
@property (nonatomic,strong) UIView *contentView;
@end

@implementation ScrollerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"测试的scroller";
    _scroller = [[UIScrollView alloc] init];
    _contentView = [[UIView alloc] init];
    
    [self.view addSubview:_scroller];
    [self.scroller addSubview:_contentView];
    
    self.scroller.backgroundColor = [UIColor redColor];
    [_scroller mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.view);
    }];
    
    _contentView.backgroundColor = [UIColor lightGrayColor];
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_scroller);
        make.width.equalTo(_scroller);
    }];
    
    UILabel *lbl = [[UILabel alloc] init];
    lbl.text = @"测试lbl";
    lbl.textColor = [UIColor blackColor];
    [self.contentView addSubview:lbl];
    
    [lbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_contentView).offset(10);
        make.right.equalTo(_contentView).offset(-10);
        make.height.mas_equalTo(@40.0f);
        make.top.equalTo(_contentView).offset(10);
    }];
    
    UILabel *lbl2 = [[UILabel alloc] init];
    lbl2.text = @"一个底部lbl2";
    lbl2.textColor = [UIColor blackColor];
    [_contentView addSubview:lbl2];
    [lbl2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(lbl);
        make.top.equalTo(lbl.mas_bottom).offset(600);
        make.height.mas_equalTo(@40.0f);
    }];
    
    
    __block MASConstraint *bottomConstraint;
    [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
       bottomConstraint = make.bottom.equalTo(lbl2);
    }];
    
    //[bottomConstraint uninstall];
}
@end

(二)上下拖动效果图;


你可能感兴趣的:(自适应,masonry)