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];

     
  • 相关阅读:
    关于 CS1595 MS的知识库还是不全面,反正它给我的解决方法不能用,偶只有这样做了....
    被一贴,一个以前写的邮件发送的小类库。记住了,不是内裤
    [下载]活学活用DataGrid控件与ADO.NET
    不同浏览器透明度的写法
    通过文件读取oep值
    菜单
    CWnd::OnContextMenu函数(右键单击弹出快捷菜单)
    poj 3349(hash)
    poj 3009(dfs+回溯 模拟)
    poj 3026 (bfs+prim)
  • 原文地址:https://www.cnblogs.com/CLiOS/p/5280934.html
Copyright © 2011-2022 走看看