码迷,mamicode.com
首页 > 移动开发 > 详细

AppManager(demo16.03.15)

时间:2015-03-16 22:35:54      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

//
//  ViewController.m
//  AppManager
//
//  Created by xin on 15-3-16.
//  Copyright (c) 2015年 Jackey. All rights reserved.
//

#import "ViewController.h"


//1 get the data
//2 draw the view
@interface ViewController ()

//
@property (nonatomic,strong) NSArray *appList;
@end

@implementation ViewController

-(NSArray *)appList{
    if(!_appList){
        NSString *path = [[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil];
        _appList = [[NSArray alloc]initWithContentsOfFile:path];
    }
    return _appList;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    int totalCol = 3;
    CGFloat viewW = 80;
    CGFloat viewH = 90;
    
    CGFloat marginX = (self.view.bounds.size.width-viewW*totalCol)/(totalCol+1);
    CGFloat marginY =10;
    CGFloat startY = 20;
    //int count = self.appList.count;
    for(int i=0;i<self.appList.count;i++){
        int row =i/totalCol;
        int col = i%totalCol;
        
        CGFloat x = marginX +(marginX+viewW)*col;
        CGFloat y =startY+ marginY +(marginY+viewH)*row;
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(x, y, viewW, viewH)];
        //view.backgroundColor = [UIColor redColor];
        [self.view addSubview:view];
        
        //image
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, viewW, 50)];
        //imageView.backgroundColor = [UIColor grayColor];
        UIImage *image = [UIImage imageNamed:self.appList[i][@"icon"]];
        imageView.image = image;
        //按照比例现实图像
        imageView.contentMode = UIViewContentModeScaleAspectFit;
        [view addSubview: imageView];
        
        //description
        UILabel *descriptionLabel = [[UILabel alloc]initWithFrame:CGRectMake(0,imageView.bounds.size.height, viewW, 20)];
        //descriptionLabel.backgroundColor = [UIColor blackColor];
        descriptionLabel.text = self.appList[i][@"name"];
        descriptionLabel.font =[UIFont systemFontOfSize:12.0];
        descriptionLabel.textAlignment = NSTextAlignmentCenter;
        [view addSubview:descriptionLabel];
        
        //button
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(0, 70, viewW, 20);
        [button setTitle:@"下载" forState:UIControlStateNormal];
        button.titleLabel.font = [UIFont systemFontOfSize:14.0];
        //button.backgroundColor = [UIColor purpleColor];
        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
        [button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
        [view addSubview:button];
        
    }
    
}

@end

添加按钮事件和动画

button.tag = i;
        
        [button addTarget:self action:@selector(downloadClick:) forControlEvents:UIControlEventTouchUpInside];

  

-(void)downloadClick:(UIButton *)button{
    UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake(80, 400, 160, 40)];
    lable.textAlignment = NSTextAlignmentCenter;
    lable.backgroundColor = [UIColor lightGrayColor];
    NSDictionary *dict = self.appList[button.tag];
    lable.text = [NSString stringWithFormat:@"下载%@完成",dict[@"name"]];
    
    lable.font = [UIFont systemFontOfSize:13.0];
    lable.alpha = 1.0;
    [self.view addSubview:lable];
    
    //动画效果
    //[UIView beginAnimations:nil context:nil];
    //[UIView setAnimationDuration:1.0];
    //lable.alpha = 1.0;
    //[UIView commitAnimations];
    
    [UIView animateWithDuration:1.0 animations:^{
        lable.alpha=0.0;
    } completion:^(BOOL finished) {
        [lable removeFromSuperview];
    }];
    
    
}

  

AppManager(demo16.03.15)

标签:

原文地址:http://www.cnblogs.com/lihaozhou/p/4342936.html

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