IOS开发for循环创建button

来源:互联网 发布:淘宝买电器靠谱吗 编辑:程序博客网 时间:2024/06/06 00:23

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];    }



0 0