1.for循环创建button
@interface LoopButtonView ()
// 按钮数组
@property (nonatomic, strong) NSMutableArray *btnArray;
// 选中按钮
@property (nonatomic, strong) UIButton *selectedBtn;
@end
@implementation LoopButtonView
-(instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
self.btnArray = [NSMutableArray array];
}
return self;
}
- (void)addOptionBtn:(NSArray *)btnArr
{
// 1.删掉之前的所有按钮
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
// 2.添加新的待选按钮
int count = (int) btnArr.count;
int totalColumns = 7;//修改此值排列按钮有几列
int totalRow;//总行数
if (count % totalColumns != 0) {
totalRow = count/totalColumns+1;
}else{
totalRow = count/totalColumns;
}
for (int i = 0; i<count; i++) {
// 1.取模型数据
// BtnParamsModel *model = [BtnParamsModel