从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
- 从0开始学习OC程序-第14天
- 从0开始学习OC程序-第1天
- 从0开始学习OC程序-第2天
- 从0开始学习OC程序-第3天
- 从0开始学习OC程序-第4天
- 从0开始学习OC程序-第5天
- 从0开始学习OC程序-第6天
- 从0开始学习OC程序-第7天
- 从0开始学习OC程序-第8天
- 从0开始学习OC程序-第9天
- 从0开始学习OC程序-第10天
- 从0开始学习OC程序-第11天
- 从0开始学习OC程序-第12天
- 从0开始学习OC程序-第13天
- 从0开始学习SpringBoot-第1天
- 从0开始学习SpringBoot-第2天
- 从0开始学习SpringBoot-第3天
- 开始学OC【第8天】
- 找工作
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (
- C++的一个奇技淫巧
- 图的邻接多重表和搜索(C++版本)
- Error:Cause: failed to find target with hash string 'N' in: F:\Androidstudio\android-sdk-windows <a
- 从0开始学习OC程序-第14天
- Xcode bundle version 如何自动增加
- 前端基础汇总
- 从服务器返回了一个参照
- Android偷懒代码块之--获取当前时间
- ThreadPoolExecutor中运行线程名称的修改
- 关于使用jar包方法冒红的解决办法及其原因
- 银行卡,IC卡,接触/非接触卡,CPU卡,NFC小结
- 最大值法灰度化