从0开始学习OC程序-第14天

来源:互联网 发布:软件开发课程设计 编辑:程序博客网 时间:2024/05/16 01:57
////  ViewController.m//  IOS第一天学习////  Created by 北国 on 16/3/18.//  Copyright © 2016年 beiguo. All rights reserved.//#import "ViewController.h"#define xJianGe 10#define yJianGe 20#define xGeShu 3#define yGeShu 4#define iconWidth 40@interface ViewController ()@property (nonatomic,strong) NSArray *appList;@end@implementation ViewController-(NSArray *)appList{    if(_appList == nil){        _appList = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil]];    }    return _appList;}- (void)viewDidLoad {    [super viewDidLoad];    //NSArray *ar = [[NSBundle mainBundle] loadNibNamed:@"Test" owner:nil options:nil];    //NSLog(@"%@",ar);    CGFloat marginX = (self.view.bounds.size.width - xJianGe * (xGeShu + 1) ) / xGeShu;    CGFloat marginY = (self.view.bounds.size.height - yJianGe * (yGeShu +1)) / yGeShu;    for(int i=0;i<yGeShu;i++){        for(int j = 0;j<xGeShu;j++){            UIView *view = [[UIView alloc] initWithFrame:CGRectMake(xJianGe*(j+1)+j*marginX, yJianGe*(i+1)+i*marginY, marginX, marginY)];            UIImageView *icon = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,marginX,marginY-40)];            icon.contentMode = UIViewContentModeScaleAspectFit;            NSDictionary *dic = self.appList[i*xGeShu+j];            icon.image = [UIImage imageNamed:dic[@"icon"]];            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(icon.frame), marginX, 20)];            label.text = dic[@"name"];            label.font = [UIFont systemFontOfSize:13];            label.textAlignment = NSTextAlignmentCenter;            UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(label.frame), marginX, 20)];            button.tag = i*xGeShu+j;            [button setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted.png"] forState:UIControlStateNormal];            [button setTitle:@"下载" forState:UIControlStateNormal];            [button addTarget:self action:@selector(clickButton:) forControlEvents:UIControlEventTouchUpInside];            [self.view addSubview:view];            [view addSubview:icon];            [view addSubview:label];            [view addSubview:button];        }    }}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];}- (void)clickButton:(UIButton*)button{    NSLog(@"%s,%ld",__func__,button.tag);    UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width/2 - 100,self.view.bounds.size.height-60, 200, 50)];    label1.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.2];    label1.text = self.appList[button.tag][@"name"] ;    label1.textAlignment = NSTextAlignmentCenter;    [self.view addSubview:label1];    label1.alpha = 0.0;    [UIView animateWithDuration:2.0f animations:^{        label1.alpha = 1.0;        [UIView animateWithDuration:2.0f animations:^{            label1.alpha = 0.0;        } completion:^(BOOL finished) {            [label1 removeFromSuperview];        }];    }];}@end
0 0
原创粉丝点击