标签:
#import "ViewController.h" #import "JWApp.h" #import "JWAppView.h"
@interfaceViewController ()
@property (strong, nonatomic) NSArray *appDatas;
@end
@implementation ViewController
-(NSArray *)appDatas { if (!_appDatas) {
NSString *path = [[NSBundlemainBundle]pathForResource:@"app.plist"ofType:nil];
NSArray *allAppArr = [NSArrayarrayWithContentsOfFile:path];
// 存放JWApp对象 NSMutableArray *tempArr = [NSMutableArrayarray];
// 遍历出plist中的所有对象【即:字典】 for (NSDictionary *dict in allAppArr) { // 拿出每个字典转成JWApp对象 // JWApp *app = [[JWApp alloc]initWithDict:dict]; JWApp *app = [JWAppappWithDict:dict];// 类方法直接转成对象 [tempArr addObject:app]; }
// _appDatas放的是JWApp对象 _appDatas = tempArr; } return_appDatas; }
- (void)viewDidLoad { [superviewDidLoad];
// 布局 int totolCol = 3;
CGFloat viewW = 80; CGFloat viewH = 90; CGFloat Margin = (self.view.bounds.size.width - totolCol * viewW) / (totolCol + 1);
for (int i = 0 ; i < self.appDatas.count; i ++) {
// 自定义的view JWAppView *view = [JWAppViewappView]; // 控制器传数据自定义的View view.app = self.appDatas[i];
[self.viewaddSubview:view];
// 返回数组(xib里面的所有东西) // UIView *view = [[[NSBundle mainBundle]loadNibNamed:@"AppView" owner:nil options:nil] firstObject]; // view.backgroundColor = [UIColor redColor];
// 设置frame
int row = i / totolCol; int col = i % totolCol;
CGFloat viewX = Margin + (viewW + Margin) * col; CGFloat viewY = 20 + (viewH + Margin) * row;
view.frame = CGRectMake(viewX, viewY, viewW, viewH);
// // 初始化子控件 // UIImageView *iconImgV = (UIImageView *)[view viewWithTag:100]; // iconImgV.image = app.image; // //// // 设置图片不拉伸 //// iconImgV.contentMode = UIViewContentModeScaleAspectFit; //// //// [view addSubview:iconImgV]; // // // UILabel *titleLabel = (UILabel *)[view viewWithTag:200]; // titleLabel.text = app.name; // //// titleLabel.font = [UIFont systemFontOfSize:13]; //// titleLabel.textAlignment = NSTextAlignmentCenter; //// [view addSubview:titleLabel]; // // UIButton *downBtn = (UIButton *)[view viewWithTag:300]; //// [downBtn setTitle:@"下载" forState:UIControlStateNormal]; // //// [downBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; //// [downBtn setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal]; //// [downBtn setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted]; // // [downBtn addTarget:self action:@selector(downLoad:) forControlEvents:UIControlEventTouchUpInside]; //// [view addSubview:downBtn]; // // // [self.view addSubview:view]; } }
//-(void)downLoad:(UIButton *)btn //{ // //}
@end |
标签:
原文地址:http://www.cnblogs.com/GhostKZShadow/p/5108777.html