标签:
代码:
- (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