AppManager(demo16.03.15)

技术分享

//
//  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];
    }];
    
    
}

  

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。