masonry写等距离布局、

-(void)initview
{
    
        __weak HomePageViewController * sv = self;
        UIScrollView *scrollView = [UIScrollView new];
        scrollView.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:scrollView];
    
        [scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(sv.view);
        }];
        UIView *container = [UIView new];
        [scrollView addSubview:container];
        [container mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(scrollView);
            make.width.equalTo(scrollView);
        }];
        int count = 10;
        UIView *lastView = nil;
        for ( int i = 0 ; i < count ; ++i )
        {
            UIView *subv = [UIView new];
            [container addSubview:subv];
            subv.backgroundColor = [UIColor colorWithHue:( arc4random() % 256 / 256.0 )
                                              saturation:( arc4random() % 128 / 256.0 ) + 0.5
                                              brightness:( arc4random() % 128 / 256.0 ) + 0.5
                                                   alpha:1];
    
            [subv mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.and.right.equalTo(container);
                make.height.mas_equalTo(@(20*i));
    
                if ( lastView ) {
                    make.top.mas_equalTo(lastView.mas_bottom);
                } else {
                    make.top.mas_equalTo(container.mas_top);
                }
            }];
    
    
            lastView = subv;
        }
        [container mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.equalTo(lastView.mas_bottom);
      }];
}

 
posted @ 2015-11-18 17:27  沧海小鱼儿  阅读(300)  评论(0编辑  收藏  举报