当前位置 : 主页 > 手机开发 > ROM >

Masonry 等间隔或等宽高排列多个控件

来源:互联网 收集:自由互联 发布时间:2021-06-10
- ( void )viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. _masonryViewArray = [NSMutableArray array]; for ( int i = 0 ; i 14 ; i++ ) { UIView *view = [[UIView alloc] init]; view.ba
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    _masonryViewArray = [NSMutableArray array];
    for (int i = 0; i<14; i++) {
        UIView *view = [[UIView alloc] init];
        view.backgroundColor = [UIColor redColor];
        view.frame = CGRectMake(0, 0, 80, 80);
        [self.view addSubview:view];
        [_masonryViewArray addObject:view];
    }
    [self test_masonry_vertical_fixItemWidth];
    [self.view updateConstraintsIfNeeded];
}


- (void)test_masonry_horizontal_fixSpace{
    //实现masonry水平固定间隔方法
    [self.masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:30 leadSpacing:10 tailSpacing:10];
    //设置array的垂直方向的约束
    [self.masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(150);
        make.height.equalTo(80);
    }];
}

- (void)test_masonry_horizontal_fixItemWidth{
    //实现masonry水平固定空间宽度方法
    [self.masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:80 leadSpacing:10 tailSpacing:10];
    //设置array的垂直方向的约束
    [self.masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(150);
        make.height.equalTo(80);
    }];
}

- (void)test_masonry_vertical_fixSpace{
    //实现masonry垂直固定控件高度方法
    [self.masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedSpacing:30 leadSpacing:10 tailSpacing:10];
    //设置array的水平方向的约束
    [self.masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(150);
        make.width.equalTo(80);
    }];
}

- (void)test_masonry_vertical_fixItemWidth{
    //实现masonry垂直固定控件高度方法
    [self.masonryViewArray mas_distributeViewsAlongAxis:MASAxisTypeVertical withFixedItemLength:80 leadSpacing:10 tailSpacing:10];
    //设置array的水平方向的约束
    [self.masonryViewArray mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(150);
        make.width.equalTo(80);
    }];
}
网友评论