美文网首页
根据数组个数 创建N行M列按钮

根据数组个数 创建N行M列按钮

作者: 没错就是豪哥灬 | 来源:发表于2018-03-29 14:29 被阅读11次

    #define PriceLabelWidth 100*SCREEN_RATIO // 价格label的宽

    #define PriceLabelHeight    30*SCREEN_RATIO            // 价格label的高

    #define TransverseSpace    (SCREEN_WIDTH-3*100*SCREEN_RATIO)/4  //横间距

    #define HeightSpace        2*SCREEN_RATIO                    // 竖间距

    for (int i = 0; i< greadPriceArr.count; i++)

                {

    这里  M 需要换成每一行控件 的个数

                    NSInteger lie = i % (M);//余数 为 0 1 2 (控制 X)

                    NSInteger row = i / M ; // 商 为 0 1 2 3 4 5 6 7 8 ... (控制Y)

                    UILabel*priceLabel=[[UILabel alloc]init];

                    priceLabel.frame=CGRectMake(lie*(PriceLabelWidth+TransverseSpace)+TransverseSpace, row*(HeightSpace+PriceLabelHeight+HeightSpace+CountLabelHeight)+HeightSpace, PriceLabelWidth, PriceLabelHeight);

                [self addSubview:priceLabel];

                }

    相关文章

      网友评论

          本文标题:根据数组个数 创建N行M列按钮

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