星空网 > 软件开发 > 操作系统

应用程序下载

 

 

#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 UIImageView *iconImage;

@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

 

- (IBAction)btnClick:(UIButton *)sender;

 

 

@end

@implementation CZAppView

 

- (void)setApp:(CZApp *)app

{

    self.iconImage.image = [UIImage imageNamed:app.icon];

    self.nameLabel.text = app.name;

}

 

- (IBAction)btnClick:(UIButton *)sender

{

    //1.让按钮禁用

    sender.enabled = NO;

    

    //2.让屏幕中间显示一个文字

    UILabel *label = [[UILabel alloc]init];

    //设置属性

    label.bounds = CGRectMake(0, 0, 100, 30);

    label.center = self.superview.center;

    

    //设置背景颜色

    label.backgroundColor = [UIColor blackColor];

    

    //设置文字

    label.text = @"正在下载...";

    label.textColor = [UIColor whiteColor];

    label.font = [UIFont systemFontOfSize:13];

    

    label.textAlignment = NSTextAlignmentCenter;

    

    label.alpha = 0;

    

    

    //添加到对应控件中

    [self.superview addSubview:label];

    

    //添加动画效果

    

    

    [UIView animateWithDuration:2 animations:^{

        label.alpha = 1;

    } completion:^(BOOL finished) {

        if(finished)

        {

//            [UIView animateWithDuration:2 animations:^{

//                label.alpha = 0;

//            } completion:^(BOOL finished) {

//                if(finished)

//                {

//                    [label removeFromSuperview];

//                }

//            }];

            [UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionCurveLinear animations:^{

                label.alpha = 0;

            } completion:^(BOOL finished) {

                [label removeFromSuperview];

            }];

        }

    }];

    

    

    

}

@end

 




原标题:应用程序下载

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

到菲律宾海运:https://www.goluckyvip.com/tag/96267.html
寄快递到菲律宾:https://www.goluckyvip.com/tag/96268.html
国内寄快递到菲律宾:https://www.goluckyvip.com/tag/96269.html
国内快递寄到菲律宾:https://www.goluckyvip.com/tag/96270.html
国内到菲律宾运输:https://www.goluckyvip.com/tag/96271.html
菲律宾货代:https://www.goluckyvip.com/tag/96272.html
长治婚庆女司仪和主持人:https://www.vstour.cn/a/366176.html
北京丰台区水上乐园哪家好玩?:https://www.vstour.cn/a/366177.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流