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

九宫格

时间:2016-01-07 10:04:15      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

#import "ViewController.h"

#import "JWApp.h"

#import "JWAppView.h"

 

 

@interfaceViewController ()

 

@property (strongnonatomicNSArray  *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

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