放假第一天,复习了一部分代码。。


//  ViewController.m

//  应用管理

//

//  Created by 李博 on 16/1/15.

//  Copyright © 2016 libo. All rights reserved.

//


#import "ViewController.h"


@interface ViewController ()

//创建一个数组

@property(nonatomic,strong)NSArray *apps;

@end


@implementation ViewController

-(NSArray *)apps{

    //重写get方法懒加载

    if (_apps==nil) {

        NSString *str =[[NSBundle mainBundle]pathForResource:@"apps.plist" ofType:nil];

        _apps=[NSArray arrayWithContentsOfFile:str];

    }

    return _apps;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    //计算九宫格

    int geShu=3;

    CGFloat cgh=90;

    CGFloat cgw=75;

    CGFloat ychu=30;

    CGFloat x=(320-geShu*cgw)/(geShu+1);

    

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

        //获取每个应用的数据

        //创建字典

        NSDictionary *dict=self.apps[i];

        //创建一个View

        UIView *view1 =[[UIView alloc]init];

//        view1.backgroundColor =[UIColor redColor];

        CGFloat cgx=x + (i%geShu)*(x+cgw);

        CGFloat cgy=ychu + (i/geShu)*(ychu+cgh);

        view1.frame=CGRectMake(cgx, cgy, cgw, cgh);

        //传进界面中

        [self.view addSubview:view1];

        

        //创建一个imageview

        UIImageView *imgviewIcon =[[UIImageView alloc]init];

        imgviewIcon.image=[UIImage imageNamed:dict[@"icon"]];

        CGFloat iconW=45;

        CGFloat iconH=iconW;

        CGFloat iconY=0;

        CGFloat iconX=(cgw-iconW)*0.5;

        imgviewIcon.frame=CGRectMake(iconX, iconY, iconW, iconH);

        [view1 addSubview:imgviewIcon];

        //创建一个lable

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

        lblName.text =dict[@"name"];

        lblName.font=[UIFont systemFontOfSize:12];

        lblName.textAlignment=NSTextAlignmentCenter;

        CGFloat nameW=cgw;

        CGFloat nameH=21;

        CGFloat nameX=0;

        CGFloat nameY=iconH;

        lblName.frame=CGRectMake(nameX, nameY, nameW, nameH);

        [view1 addSubview:lblName];

        //创建一个button

        UIButton *button=[[UIButton alloc]init];

        [button setTitle:@"下载" forState:UIControlStateNormal];

        [button setTitle:@"已下载" forState:UIControlStateDisabled];

        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];

        [button setBackgroundImage: [UIImage imageNamed:@"buttongreen_highlighted" ]forState:UIControlStateDisabled];

        [view1 addSubview:button];

        button.titleLabel.font=[UIFont systemFontOfSize:14];

        CGFloat btnW=45;

        CGFloat btnH=25;

        CGFloat btX=(cgw-btnW)*0.5;

        CGFloat btY=iconH+nameH;

        button.frame=CGRectMake(btX, btY, btnW, btnH);

        //为按钮注册一个单击事件

        [button addTarget:self action:@selector(didClickButton:) forControlEvents:UIControlEventTouchUpInside];

        [view1 addSubview:button];

        

        

    }

}

-(void)didClickButton:(UIButton *)sender{

    //设置当前控制器的view不允许和用户交互

    self.view.userInteractionEnabled=NO;

    sender.enabled=NO;

    //需要一个lable

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

    //设置按钮属性

    lbl.frame=CGRectMake(70, 250, 180, 35);

    lbl.backgroundColor=[UIColor blackColor];

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

    lbl.textColor=[UIColor whiteColor];

    lbl.font=[UIFont systemFontOfSize:16];

    lbl.textAlignment=NSTextAlignmentCenter;

    lbl.alpha=0.7;

    lbl.layer.cornerRadius=5;

    lbl.layer.masksToBounds=YES;

    [self.view addSubview:lbl];

    [UIView animateWithDuration:1.5 animations:^{

        lbl.alpha=0.0;

    } completion:^(BOOL finished){

        [lbl removeFromSuperview];

        self.view.userInteractionEnabled=YES;

    }];

    

    

    

    

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}


@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值