美文网首页
ios for循环添加按钮

ios for循环添加按钮

作者: 你又脸红了i | 来源:发表于2018-11-09 15:59 被阅读0次

定义宏

#define Start_X          30.0f      // 第一个按钮的X坐标

#define Start_Y          30.0f    // 第一个按钮的Y坐标

#define Width_Space      70.0f      // 2个按钮之间的横间距

#define Height_Space    0.0f    // 竖间距

#define Button_Height  60.0f    // 高

#define Button_Width    60.0f    // 宽

for(int i =0; i <3; i++) {

            NSIntegerindex = i %3;

            NSIntegerpage = i /3;

            // 圆角按钮

            UIButton *mapBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];

            mapBtn.tag= i;//这句话不写等于废了

            mapBtn.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);

            mapBtn.backgroundColor= [UIColorblackColor];

            [celladdSubview:mapBtn];

            //按钮点击方法

            [mapBtnaddTarget:self action:@selector(mapBtnClick:) forControlEvents:UIControlEventTouchUpInside];

        }

相关文章

网友评论

      本文标题:ios for循环添加按钮

      本文链接:https://www.haomeiwen.com/subject/vqeoxqtx.html