添加九宫格

代码:

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

        

    }

 

    

}

 

posted on 2015-05-22 20:38  姚华玲  阅读(166)  评论(0编辑  收藏  举报

导航