您的位置:首页 > 移动开发 > IOS开发

IOS开发for循环创建button

2016-03-25 20:30 477 查看

for循环创建button

for (int i = 0; i < 9; i++)
{
int a = i/4;   //取余
int b = i%4;   //取整
UIButton *tagButton = [[UIButton alloc] initWithFrame:CGRectMake(20+(10+(kScreenWidth-6)/5)*b, 90+(20+10)*a, (kScreenWidth-6)/5, 20)];
tagButton.layer.borderColor = MyHexColor(@"ee2266").CGColor;
tagButton.layer.borderWidth = 1;
tagButton.layer.cornerRadius = 5;
tagButton.tag = i;
tagButton.titleLabel.font = [UIFont systemFontOfSize:12];
[tagButton setTitle:_buttonArray[i] forState:UIControlStateNormal];
[tagButton setTitleColor:MyHexColor(@"ee2266") forState:UIControlStateNormal];
[tagButton addTarget:self action:@selector(tagButtonAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:tagButton];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: