在iOS开发的时候可能会碰到一个问题、并排的多个Button 我们不知道怎么用Masonry去实现、下面就是用Masonry去实现的
- (void)setTitleArr:(NSArray *)titleArr
{
NSMutableArray *arrayMut = [NSMutableArray array];
for (int i = 0; i<titleArr.count; i++) {
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tag = 1000+i;
[btn setTitle:titleArr[i] forState:UIControlStateNormal];
[btn addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
[btn setBackgroundColor:[UIColor whiteColor]];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self addSubview:btn];
[arrayMut addObject:btn];
}
if (arrayMut.count <= 0) {
return;
}
_lineView = [[UIView alloc] init];
_lineView.backgroundColor = [UIColor redColor];
[self addSubview:_lineView];
[_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.bottom.equalTo(@0);
make.size.mas_equalTo(CGSizeMake(UIScreenWidth/titleArr.count, 2.5));
}];
[arrayMut mas_distributeViewsAlongAxis:MASAxisTypeHorizontal
withFixedSpacing:0 //item间距
leadSpacing:0 //起始间距
tailSpacing:0]; //结尾间距
[arrayMut mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(@0);
// make.bottom.mas_equalTo(_lineView.mas_top).equalTo(@0);
make.bottom.equalTo(@-2.5);
}];
}