应用管理之Interface
2015-06-27 21:19
399 查看
1.知识点:数组,字典,UIImageView,UILabel,UIButton
2.初始化数组:@property(nonatomic,strong) NSArray *apps;
- (NSArray *)apps
{
if (_apps == nil) {
// 1.获得plist的全路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil];
// 2.加载数组
_apps = [NSArray arrayWithContentsOfFile:path];
}
return _apps;
}
3.加载图片,设置lable和button
- (void)viewDidLoad
{
[super viewDidLoad];
// self.apps;
// 添加应用
// 应用的尺寸
CGFloat appW = 85;
CGFloat appH = 90;
// 总列数
int totalColumns = 3;
// 间隙 = (控制器view的宽度 - 3*应用宽度) / 4
CGFloat margin = (self.view.frame.size.width - totalColumns*appW) / (totalColumns + 1);
CGFloat appX = margin;
CGFloat appY = 30;
加12个UIVIiew小框框
// 调用apps的getter方法
for (int index = 0; index < self.apps.count; index ++) {
// 行号
int line = index / totalColumns;
// 列号
int row = index % totalColumns;
UIView *appView = [[UIView alloc]init];
// appView.backgroundColor = [UIColor redColor];
appView.frame = CGRectMake(appX + (appW + margin)*row, appY + (appH + margin)*line, appW, appH);
[self.view addSubview:appView];
NSDictionary *appInfo = self.apps[index];
// 添加内部小组件
// 添加图片
UIImageView *imageView = [[UIImageView alloc]init];
CGFloat iconW = 60;
CGFloat iconH = 50;
CGFloat iconX = (appW - iconW)*0.5;
CGFloat iconY = 0;
imageView.frame = CGRectMake(iconX, iconY, iconW, iconH);
// imageView.backgroundColor = [UIColor blackColor];
// 加载图片
imageView.image = [UIImage imageNamed:appInfo[@"icon"]];
[appView addSubview:imageView];
// 添加名字
UILabel *nameLabel = [[UILabel alloc]init];
CGFloat nameW = 65;
CGFloat nameH = 20;
CGFloat nameX = (appW - nameW)*0.5;
CGFloat nameY = iconY + iconH;
nameLabel.frame = CGRectMake(nameX, nameY, nameW, nameH);
// nameLabel.backgroundColor = [UIColor yellowColor];
// 加载名字
nameLabel.text = appInfo[@"name"];
nameLabel.font = [UIFont systemFontOfSize:12]; // 字体大小
nameLabel.textAlignment = NSTextAlignmentCenter; // 字体居中
[appView addSubview:nameLabel];
// 添加下载按钮
UIButton *button =[[UIButton alloc]init];
CGFloat buttonW = 65;
CGFloat butttonH = 20;
CGFloat buttonX = (appW - nameW)*0.5;
CGFloat buttonY = iconY + iconH + nameH;
button.frame = CGRectMake(buttonX, buttonY, buttonW, butttonH);
button.backgroundColor = [UIColor grayColor];
// 设置普通状态下的图片
UIImage *normalImage = [UIImage imageNamed:@"buttongreen"];
[button setBackgroundImage:normalImage forState:UIControlStateNormal];
// 设置高亮状态下的图片
UIImage *highImage = [UIImage imageNamed:@"buttongreen_highlighted"];
[button setBackgroundImage:highImage forState:UIControlStateHighlighted];
[button setTitle:@"下载" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:13]; // 按钮改变字体 按钮内部有个label
[appView addSubview:button];
}
}
4.Button类里有UILabel,UIImageView属性,设置Button的字体的时候,通过label设置
button.titleLabel.font = [UIFont systemFontOfSize:13]; // 按钮改变字体 按钮内部有个label
5.开发中应尽可能加大代码的可扩展性增强,不仅仅是实现了现有的功能
通过把fram的各个属性拿出来单独赋值---方便修改每个视图的位置(当几个视图同时有一个父视图的情况更加明显)
根据索引取出数组元素即对应的字典 通过字典导出应用图标对应图片的名称 通过对用字典的key值(name)导出应用的名称
6.搭建九宫格的步骤
明确每一块用的是什么view
明确每个view之间的父子关系
先尝试逐个添加格子,最后考虑使用for循环
加载app数据,根据数据长度创建对应个数的格子
添加格子内部的子控件
给格子内部的子控件装配数据
2.初始化数组:@property(nonatomic,strong) NSArray *apps;
- (NSArray *)apps
{
if (_apps == nil) {
// 1.获得plist的全路径
NSString *path = [[NSBundle mainBundle] pathForResource:@"app.plist" ofType:nil];
// 2.加载数组
_apps = [NSArray arrayWithContentsOfFile:path];
}
return _apps;
}
3.加载图片,设置lable和button
- (void)viewDidLoad
{
[super viewDidLoad];
// self.apps;
// 添加应用
// 应用的尺寸
CGFloat appW = 85;
CGFloat appH = 90;
// 总列数
int totalColumns = 3;
// 间隙 = (控制器view的宽度 - 3*应用宽度) / 4
CGFloat margin = (self.view.frame.size.width - totalColumns*appW) / (totalColumns + 1);
CGFloat appX = margin;
CGFloat appY = 30;
加12个UIVIiew小框框
// 调用apps的getter方法
for (int index = 0; index < self.apps.count; index ++) {
// 行号
int line = index / totalColumns;
// 列号
int row = index % totalColumns;
UIView *appView = [[UIView alloc]init];
// appView.backgroundColor = [UIColor redColor];
appView.frame = CGRectMake(appX + (appW + margin)*row, appY + (appH + margin)*line, appW, appH);
[self.view addSubview:appView];
NSDictionary *appInfo = self.apps[index];
// 添加内部小组件
// 添加图片
UIImageView *imageView = [[UIImageView alloc]init];
CGFloat iconW = 60;
CGFloat iconH = 50;
CGFloat iconX = (appW - iconW)*0.5;
CGFloat iconY = 0;
imageView.frame = CGRectMake(iconX, iconY, iconW, iconH);
// imageView.backgroundColor = [UIColor blackColor];
// 加载图片
imageView.image = [UIImage imageNamed:appInfo[@"icon"]];
[appView addSubview:imageView];
// 添加名字
UILabel *nameLabel = [[UILabel alloc]init];
CGFloat nameW = 65;
CGFloat nameH = 20;
CGFloat nameX = (appW - nameW)*0.5;
CGFloat nameY = iconY + iconH;
nameLabel.frame = CGRectMake(nameX, nameY, nameW, nameH);
// nameLabel.backgroundColor = [UIColor yellowColor];
// 加载名字
nameLabel.text = appInfo[@"name"];
nameLabel.font = [UIFont systemFontOfSize:12]; // 字体大小
nameLabel.textAlignment = NSTextAlignmentCenter; // 字体居中
[appView addSubview:nameLabel];
// 添加下载按钮
UIButton *button =[[UIButton alloc]init];
CGFloat buttonW = 65;
CGFloat butttonH = 20;
CGFloat buttonX = (appW - nameW)*0.5;
CGFloat buttonY = iconY + iconH + nameH;
button.frame = CGRectMake(buttonX, buttonY, buttonW, butttonH);
button.backgroundColor = [UIColor grayColor];
// 设置普通状态下的图片
UIImage *normalImage = [UIImage imageNamed:@"buttongreen"];
[button setBackgroundImage:normalImage forState:UIControlStateNormal];
// 设置高亮状态下的图片
UIImage *highImage = [UIImage imageNamed:@"buttongreen_highlighted"];
[button setBackgroundImage:highImage forState:UIControlStateHighlighted];
[button setTitle:@"下载" forState:UIControlStateNormal];
button.titleLabel.font = [UIFont systemFontOfSize:13]; // 按钮改变字体 按钮内部有个label
[appView addSubview:button];
}
}
4.Button类里有UILabel,UIImageView属性,设置Button的字体的时候,通过label设置
button.titleLabel.font = [UIFont systemFontOfSize:13]; // 按钮改变字体 按钮内部有个label
5.开发中应尽可能加大代码的可扩展性增强,不仅仅是实现了现有的功能
通过把fram的各个属性拿出来单独赋值---方便修改每个视图的位置(当几个视图同时有一个父视图的情况更加明显)
根据索引取出数组元素即对应的字典 通过字典导出应用图标对应图片的名称 通过对用字典的key值(name)导出应用的名称
6.搭建九宫格的步骤
明确每一块用的是什么view
明确每个view之间的父子关系
先尝试逐个添加格子,最后考虑使用for循环
加载app数据,根据数据长度创建对应个数的格子
添加格子内部的子控件
给格子内部的子控件装配数据
相关文章推荐
- 关于编译报错“dereferencing pointer to incomplete type...
- leetcode--CourseScheduleII
- C++中的sort函数
- 【Leetcode】【Easy】Isomorphic Strings
- 自动登录界面
- eclipse中hibernate配置文件自动提示
- iOS开发——CoreBluetooth蓝牙开发(二)
- C++13.3 析构函数destructor
- 多路归并使用败者树的性能分析
- 使用AsyncTask实现网络数据的异步访问
- 需求调研报告(用户需求说明书)编写规范
- Spring过滤器filter拦截服务
- 150.按规定输出
- 将IDEA快捷键改为Eclipse模式
- 去中心化:微信抄袭泛滥的原罪?
- 2015062706 - EffactiveJava笔记 - 第39条 必要时进行保护性拷贝
- cif安装错误异常处理过程记录
- MSQL优化基础(SQL执行过程,链接方式案例)
- 如何停止一个正在运行的java线程?
- C语言qsort