码迷,mamicode.com
首页 > 其他好文 > 详细

添加九宫格

时间:2015-05-22 21:07:21      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:

代码:

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    self.view.backgroundColor=[UIColor whiteColor];

    [self _loadData];

    [self _loadView];

    

    

}

 

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void)_loadView{

    NSInteger appw=100;

    NSInteger apph=130;

    NSInteger magin=(self.view.frame.size.width-(appw*3))/4;

    NSInteger place=(self.view.frame.size.height-(apph*4))/5;

   

    for (int index=0; index<_array.count; index++) {

        MyView * view=[[MyView alloc]initWithFrame:CGRectMake(magin+(index%3) *(magin+appw),20+place+(index/3)*(apph+place) , appw, apph)];

        [view setData:_array[index]];

        [self.view addSubview:view];

    }

    

    

}

 

- (void)_loadData{

    

    _array=[NSMutableArray arrayWithCapacity:10];

    

  //从plist文件中取出来,并对象化放入数组中存如数组中

    NSString * path =[[NSBundle mainBundle]pathForResource:@"star" ofType:@"plist"];

    NSArray * array=[NSArray arrayWithContentsOfFile:path];

    

    for (NSDictionary * d in array) {

       Star * star=[[Star alloc]init];

        star.pic=d[@"pic"];

        star.name=d[@"name"];

        [_array addObject:star];

        

    }

 

    

}

 

添加九宫格

标签:

原文地址:http://www.cnblogs.com/yy515700/p/4523245.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!