1 self.itemArray = [NSMutableArray array]; 2 for (NSInteger i=0; i < 6; i++) { 3 UIButton *button = [[UIButton alloc] init]; 4 button.backgroundColor = [UIColor greenColor]; 5 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(buttonTapPressed:)]; 6 [button addGestureRecognizer:tapGesture]; 7 [self.view addSubview:button]; 8 [self.itemArray addObject:button]; 9 } 10 11 [self.itemArray mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:15 leadSpacing:10 tailSpacing:10]; 12 [self.itemArray mas_makeConstraints:^(MASConstraintMaker *make) { 13 make.top.equalTo(self.view).offset(100); 14 make.height.equalTo(@50); 15 }];
原文:https://www.cnblogs.com/xujinzhong/p/10824750.html