首页 > 其他 > 详细

添加九宫格

时间:2015-05-22 21:06:09      阅读:277      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!