zoukankan      html  css  js  c++  java
  • 九宫格布局(demo16.03.14)

    //
    //  ViewController.m
    //  AppManager
    //
    //  Created by xin on 15-3-16.
    //  Copyright (c) 2015年 Jackey. All rights reserved.
    //
    
    #import "ViewController.h"
    
    
    //1 get the data
    //2 draw the view
    @interface ViewController ()
    
    //
    @property (nonatomic,strong) NSArray *appList;
    @end
    
    @implementation ViewController
    
    -(NSArray *)appList{
        if(!_appList){
            NSString *path = [[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil];
            _appList = [[NSArray alloc]initWithContentsOfFile:path];
        }
        return _appList;
    }
    
    
    
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        
        int totalCol = 3;
        CGFloat viewW = 80;
        CGFloat viewH = 90;
        
        CGFloat marginX = (self.view.bounds.size.width-viewW*totalCol)/(totalCol+1);
        CGFloat marginY =10;
        CGFloat startY = 20;
        //int count = self.appList.count;
        for(int i=0;i<self.appList.count;i++){
            int row =i/totalCol;
            int col = i%totalCol;
            
            CGFloat x = marginX +(marginX+viewW)*col;
            CGFloat y =startY+ marginY +(marginY+viewH)*row;
            
            UIView *view = [[UIView alloc]initWithFrame:CGRectMake(x, y, viewW, viewH)];
            view.backgroundColor = [UIColor redColor];
            [self.view addSubview:view];
        }
        
    }
    
    @end
    

      

  • 相关阅读:
    threadlocal 变量 跟synchronized 关键字的关系
    Android媒体扫描详细解析之一(MediaScanner & MediaProvider)
    创建视图全文搜索[完整版]
    海量小文件问题综述
    内存拷贝探究
    case功能菜单选项
    linux case ${variable} in
    attack source code
    ftps加密服务器
    vim编程设置
  • 原文地址:https://www.cnblogs.com/lihaozhou/p/4342792.html
Copyright © 2011-2022 走看看