iOS开发,用for创建6个按钮,摆成两行三列,代码该怎么写?

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

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

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

define Height_Space 20.0f // 竖间距

define Button_Height 122.0f // 高

define Button_Width 75.0f // 宽

-(void)addButtonS
{
for (int i = 0 ; i < 6; i++) {
NSInteger index = i % 3;
NSInteger page = i / 3;

    // 圆角按钮
    UIButton *aBt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
     
    aBt.frame = CGRectMake(index * (Button_Width + Width_Space) + Start_X, page  * (Button_Height + Height_Space)+Start_Y, Button_Width, Button_Height);
     
    [self.view addSubview:aBt];
}

}

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容