AppManager(demo16.03.15)

來源:互聯網
上載者:User

標籤:

////  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)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.