首页 > 其他 > 详细

循环创建按钮

时间:2016-04-13 18:43:01      阅读:195      评论:0      收藏:0      [点我收藏+]

   CGFloat margin = 22;

    CGFloat btnW = 35;

    CGFloat btnH = 35;

    int cloums = 7;

    CGFloat btnLeft = (self.view.frame.size.width - (btnW * cloums) - (cloums - 1) * margin) / 2;

 

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

        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

        

        // 行的索引

        int colIdx = i % cloums;

        // 列的索引

        int rowIdx = i / cloums;

        CGFloat btnX = btnLeft + colIdx * (btnW + margin);

        CGFloat btnY = 0 + rowIdx * (btnH + margin);

        button.frame = CGRectMake(btnX, btnY, btnW, btnH);

        button.backgroundColor = [UIColor redColor];

        [self.view addSubview:button];

    }

循环创建按钮

原文:http://www.cnblogs.com/fantasy3588/p/5388109.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!