Masonry高级用法

346 阅读1分钟

水平方向排列、固定控件间隔、控件长度不定

    NSMutableArray *buttons = [NSMutableArray array];
    for (int i = 0; i < 2; i ++) {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setTitle:@"按钮名称" forState:UIControlStateNormal];
        [button.titleLabel setFont:FontMedium(16)];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [button setBackgroundColor:[UIColor blackColor]];
        button.tag = i + 100;
        button.layer.cornerRadius = 20;
        [button addTarget:self action:@selector(didTapButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
        [buttons addObject:button];
    } 
    [buttons mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10 leadSpacing:20 tailSpacing:20];
    [buttons mas_makeConstraints:^(MASConstraintMaker *make) {
    make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-20);
        make.height.mas_equalTo(40);
    }];

底部对齐

make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-20);