zoukankan      html  css  js  c++  java
  • 九宫格

     CGFloat bookViewW = 100;

     CGFloat bookViewH = 140;

        //(屏幕的宽度 - 一个小块的宽度 * 总的列数) / (总的列数 + 1)

        int totalColum = 3;

        int totalRow = 4;    

        CGFloat marginX = (self.view.frame.size.width - bookViewW * totalColum) / (totalColum + 1);

        CGFloat marginY = (self.view.frame.size.height - bookViewH * totalRow) / (totalRow + 1);

        NSLog(@"mX %f,mY %f",marginX,marginY);

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

         1.创建一个视图作为容器

            UIView * bookView = [[UIView alloc] init];

         2.建立父子关系,如果一个视图想要正确的显示在界面上,只要与一个已经显示在页面的视图建立父子关系就可以

            与控制器管理的默认视图,建立父子关系

            [self.view addSubview:bookView];

                  //行         

               0,1,2 —>0

               3,4,5 ->1

               int row=i/totalColum

                  //列

               0,3,6 ->0

               1,4,7 ->1

               2,5,8 ->2

               int col=i/totalRow

     

            //计算当前i 值所处在的列

            CGFloat currentColum = i % totalColum;// 0 - 2

            //计算当前i 值所处在的行

            CGFloat currentRow = i / totalColum;//0 - 3;

            CGFloat bookViewX = marginX + (marginX + bookViewW) * currentColum;

            CGFloat bookViewY = marginY + (marginY + bookViewH)  * currentRow;

          3.设置正确的Frame

            bookView.frame = CGRectMake(bookViewX, bookViewY, bookViewW, bookViewH);

            bookView.backgroundColor = [UIColor redColor];

     
  • 相关阅读:
    shell得到两个文件的差集
    shell 单引号&双引号的使用
    kubernetes session and 容器root权限
    docker 使用网络以及容器互联
    倒计时练习
    会话控制
    XML
    AJAX实现搜索智能提示
    弹窗显示详情练习
    三级联动
  • 原文地址:https://www.cnblogs.com/CLiOS/p/5280934.html
Copyright © 2011-2022 走看看