masonry

来源:互联网 发布:中国禁枪怕被推翻 知乎 编辑:程序博客网 时间:2024/06/02 04:25

//fixedItemWidth: 宫格的宽度,如果设置为0的话,则由父容器控制宽度,如果不为零,则可以控制父容器的宽度
   //fixedItemHeight:与fixedItemWidth同理
   //fixedLineSpacing:宫格之间行的间距,如果宫格只有一行,则不生效
   //fixedInteritemSpacing:宫格之间列的间距,如果只有一列,则不生效
   //warpCount:折行的位置,如果设置为3,则表示该九宫格需要布局3列,值得一提的是,如果NSArray本身的count如果小于warpCount,则该函数会用空的UIView填充到缺失区域。
   //topSpacing:bottomSpacing:leadSpacing:tailSpacing:九宫格顶边距,底边距,左边距以及右边距,不多说


     // 执行九宫格布局
    [containerView.subviews mas_distributeSudokuViewsWithFixedItemWidth:0 fixedItemHeight:0 fixedLineSpacing:10 fixedInteritemSpacing:20 warpCount:3 topSpacing:10 bottomSpacing:10 leadSpacing:10 tailSpacing:10];






    make.right.lessThanOrEqualTo(-80).priorityHigh();
    make.size.equalTo(CGSizeMake(150, 100));
    make.edges.equalTo(myView).insets(UIEdgeInsetsMake(10, 5, 15, 5));
     make.center.equalTo(myView).centerOffset(CGPointMake(-10, 10));


 - (void)masonryScrollView
{
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    [self.view addSubview:scrollView];
    [scrollView makeConstraints:^(MASConstraintMaker *make) {
    }];
    
    UIView *containerView = [[UIView alloc] init];
    [scrollView addSubview:containerView];
    [containerView makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(scrollView);
        make.width.equalTo(scrollView.mas_width);
    }];
    
    [containerView updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(lastView.mas_bottom).offset(20);
    }];
}




    UIView *lastView = nil;
    for (NSInteger i = 0; i < 10; i++) {
        UIView *view = [[UIView alloc] init];
        [containerView addSubview:view];
        if (!lastView) {
            [view makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(containerView.mas_top);
            }];
        }else
        {
            [view makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(lastView.mas_bottom).offset(10);
            }];
        }
        lastView = view;
    }

原创粉丝点击