设为首页 加入收藏

TOP

应用程序下载(一)
2017-10-13 10:32:56 】 浏览:2150
Tags:应用 程序下载

 

 

#import "ViewController.h"

#import "CZApp.h"

#import "CZAppView.h"

@interface ViewController ()

@property(nonatomic,strong)NSArray *appArray;

@end

 

@implementation ViewController

 

//懒加载

-(NSArray *)appArray

{

    if(_appArray == nil)

    {

        NSBundle *bundle = [NSBundle mainBundle];

        NSString *path = [bundle pathForResource:@"app" ofType:@"plist"];

        NSArray *arr = [[NSArray alloc] init];

        arr = [NSArray arrayWithContentsOfFile:path];

        

        

        //字典转模型

        //1.定义可变数组

        NSMutableArray *Marr = [NSMutableArray array];

        //2.遍历字典数组

        for(NSDictionary *dict in arr)

        {

            //字典转模型

            CZApp *app = [CZApp appWithDict:dict];

            

            //将模型添加到可变数组中

            [Marr addObject:app];

            

        }

        //将模型数组赋值给字典数字

        _appArray = Marr;

    }

    return _appArray;

}

 

 

- (void)viewDidLoad {

    [super viewDidLoad];

#define KUIViewCol 3

#define KUIViewW 80

#define KUIViewH 100

    CGFloat Margin = (self.view.frame.size.width - KUIViewCol*KUIViewW)/(KUIViewCol+1);

    for(int i = 0;i<self.appArray.count;i++)

    {

        NSInteger row = i/KUIViewCol;

        NSInteger col = i%KUIViewCol;

        

        CGFloat viewX = Margin + col*(KUIViewW+Margin);

        CGFloat viewY = Margin + row*(KUIViewH+Margin);

        

        //1.创建控件对象

        //UIView *appView = [UIView alloc]init];等同于下面

        CZAppView *appView =[[[NSBundle mainBundle]loadNibNamed:@"CZAppView" owner:nil options:nil] lastObject];

        //2.设置属性,优先设置frame

        appView.frame = CGRectMake(viewX, viewY, appView.bounds.size.width, appView.bounds.size.height);

        

        //2.1 获取数据

        CZApp *app = self.appArray[i];

        

        

        //2.2传入数据

        [appView setApp:app];

        

        

        //3.添加到对应控件中

        

        [self.view addSubview:appView];        

    }

}

@end

 

 

 

//CZAPPView类

 

#import "CZAppView.h"

#import "CZApp.h"

 

@interface CZAppView ()

 

@property (weak, nonatomic) IBOutlet UIIma

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇网络安全——Base64编码、MD5、SH.. 下一篇Swift 可选值

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目