循环创建按钮
- (void)setHomeFooterViewOne {
// 一个图片的高度 margin20 = 20 像素点
CGFloatbgViewHh = (kScreenWidth-margin20*2)/3;
// 底部view 20 20
UIView*bgView = [[UIViewalloc]initWithFrame:CGRectMake(0,0,kScreenWidth, bgViewHh*2)];
bgView.backgroundColor = BGColor;
[selfaddSubview:bgView];
for(inti =0; i <6; i++) {
inta = i/3; //取余
intb = i%3; //取整
UIButton*tagButton = [[UIButtonalloc]initWithFrame:CGRectMake(margin20+ bgViewHh * b, bgViewHh * a, bgViewHh, bgViewHh)];
tagButton.layer.borderColor=redColor1.CGColor;
tagButton.layer.borderWidth=1;
tagButton.layer.cornerRadius=5;
tagButton.tag= i;
tagButton.titleLabel.font= [UIFontsystemFontOfSize:12];
[tagButtonsetTitle:@"i" forState:UIControlStateNormal];
[tagButtonsetTitleColor:BGColor forState:UIControlStateNormal];
[tagButtonaddTarget:self action:@selector(tagButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[selfaddSubview:tagButton];
}
}
- (void)tagButtonAction:(UIButton*)btn {
XPFLog(@" --------- ----------- --------- ");
}
![](https://img.haomeiwen.com/i1443029/f7a3bf0b24ea9a09.jpg)