iOS开发UI篇—九宫格坐标计算

时间:2023-02-12 18:13:31

iOS开发UI篇—九宫格坐标计算

一、要求

完成下面的布局

iOS开发UI篇—九宫格坐标计算

二、分析

寻找左边的规律,每一个uiview的x坐标和y坐标。

iOS开发UI篇—九宫格坐标计算

三、实现思路

(1)明确每一块用得是什么view

(2)明确每个view之间的父子关系,每个视图都只有一个父视图,拥有很多的子视图。

(3)可以先尝试逐个的添加格子,最后考虑使用for循环,完成所有uiview的创建

(4)加载app数据,根据数据长度创建对应个数的格子

(5)添加格子内部的子控件

(6)给内部的子控件装配数据

四、代码示例

 //
// YYViewController.m
// 九宫格练习
//
// Created by 孔医己 on 14-5-22.
// Copyright (c) 2014年 itcast. All rights reserved.
// #import "YYViewController.h" @interface YYViewController ()
@property(nonatomic,strong)NSArray *apps;
@end @implementation YYViewController //1.加载数据
- (NSArray *)apps
{
if (!_apps) {
NSString *path=[[NSBundle mainBundle]pathForResource:@"app.plist" ofType:nil];
_apps=[NSArray arrayWithContentsOfFile:path];
}
return _apps;
} - (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"%d",self.apps.count); //2.完成布局设计 //三列
int totalloc=;
CGFloat appvieww=;
CGFloat appviewh=; CGFloat margin=(self.view.frame.size.width-totalloc*appvieww)/(totalloc+);
int count=self.apps.count;
for (int i=; i<count; i++) {
int row=i/totalloc;//行号
//1/3=0,2/3=0,3/3=1;
int loc=i%totalloc;//列号 CGFloat appviewx=margin+(margin+appvieww)*loc;
CGFloat appviewy=margin+(margin+appviewh)*row; //创建uiview控件
UIView *appview=[[UIView alloc]initWithFrame:CGRectMake(appviewx, appviewy, appvieww, appviewh)];
//[appview setBackgroundColor:[UIColor purpleColor]];
[self.view addSubview:appview]; //创建uiview控件中的子视图
UIImageView *appimageview=[[UIImageView alloc]initWithFrame:CGRectMake(, , , )];
UIImage *appimage=[UIImage imageNamed:self.apps[i][@"icon"]];
appimageview.image=appimage;
[appimageview setContentMode:UIViewContentModeScaleAspectFit];
// NSLog(@"%@",self.apps[i][@"icon"]);
[appview addSubview:appimageview]; //创建文本标签
UILabel *applable=[[UILabel alloc]initWithFrame:CGRectMake(, , , )];
[applable setText:self.apps[i][@"name"]];
[applable setTextAlignment:NSTextAlignmentCenter];
[applable setFont:[UIFont systemFontOfSize:12.0]];
[appview addSubview:applable]; //创建按钮
UIButton *appbtn=[UIButton buttonWithType:UIButtonTypeCustom];
appbtn.frame= CGRectMake(, , , );
[appbtn setBackgroundImage:[UIImage imageNamed:@"buttongreen"] forState:UIControlStateNormal];
[appbtn setBackgroundImage:[UIImage imageNamed:@"buttongreen_highlighted"] forState:UIControlStateHighlighted];
[appbtn setTitle:@"下载" forState:UIControlStateNormal];
appbtn.titleLabel.font=[UIFont systemFontOfSize:12.0];
[appview addSubview:appbtn]; [appbtn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
} } -(void)click
{
//动画标签
UILabel *animalab=[[UILabel alloc]initWithFrame:CGRectMake(self.view.center.x-, self.view.center.y+, , )];
[animalab setText:@"下载成功"];
animalab.font=[UIFont systemFontOfSize:12.0];
[animalab setBackgroundColor:[UIColor brownColor]];
[animalab setAlpha:];
[self.view addSubview:animalab]; // [UIView beginAnimations:Nil context:Nil];
// [animalab setAlpha:1];
// [UIView setAnimationDuration:4.0];
// [UIView commitAnimations]; //执行完之后,还得把这给删除了,推荐使用block动画 [UIView animateWithDuration:4.0 animations:^{
[animalab setAlpha:];
} completion:^(BOOL finished) {
//[self.view re];
}];
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
} @end

执行效果:

iOS开发UI篇—九宫格坐标计算

iOS开发UI篇—九宫格坐标计算的更多相关文章

  1. iOS开发UI篇——九宫格坐标计算

    一.要求 完成下面的布局 二.分析 寻找左边的规律,每一个uiview的x坐标和y坐标. 三.实现思路 (1)明确每一块用得是什么view (2)明确每个view之间的父子关系,每个视图都只有一个父视 ...

  2. iOS开发——UI篇&amp&semi;九宫格算法

    九宫格算法 关于iOS开发中九宫格的实现虽然使用不多,而且后面会有更好的方实现,但是作为一个程序员必需要知道的就是九宫格算法的实现. 一:实现思路: (1)明确每一块用得是什么view (2)明确每个 ...

  3. iOS开发UI篇—简单的浏览器查看程序

    iOS开发UI篇—简单的浏览器查看程序 一.程序实现要求 1.要求 2. 界面分析 (1) 需要读取或修改属性的控件需要设置属性 序号标签 图片 图片描述 左边按钮 右边按钮 (2) 需要监听响应事件 ...

  4. iOS开发UI篇—从代码的逐步优化看MVC

    iOS开发UI篇—从代码的逐步优化看MVC 一.要求 要求完成下面一个小的应用程序. 二.一步步对代码进行优化 注意:在开发过程中,优化的过程是一步一步进行的.(如果一个人要吃五个包子才能吃饱,那么他 ...

  5. iOS开发UI篇—popoverController使用注意

    iOS开发UI篇—popoverController使用注意 一.设置尺寸 提示:不建议,像下面这样吧popover的宽度和高度写死. //1.新建一个内容控制器 YYMenuViewControll ...

  6. iOS开发UI篇—CAlayer层的属性

    iOS开发UI篇—CAlayer层的属性 一.position和anchorPoint 1.简单介绍 CALayer有2个非常重要的属性:position和anchorPoint @property ...

  7. ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布局

    本文转自 :http://www.cnblogs.com/wendingding/p/3761730.html ios开发UI篇—使用纯代码自定义UItableviewcell实现一个简单的微博界面布 ...

  8. iOS开发UI篇—xib的简单使用

    iOS开发UI篇—xib的简单使用 一.简单介绍 xib和storyboard的比较,一个轻量级一个重量级. 共同点: 都用来描述软件界面 都用Interface Builder工具来编辑 不同点: ...

  9. iOS开发UI篇—UIScrollView控件介绍

    iOS开发UI篇—UIScrollView控件介绍 一.知识点简单介绍 1.UIScrollView控件是什么? (1)移动设备的屏幕⼤大⼩小是极其有限的,因此直接展⽰示在⽤用户眼前的内容也相当有限 ...

随机推荐

  1. python的正则表达式

    1 元字符: 1.1 . .除了换行符以外的任何单个字符 1.2 ^ ^只匹配起始字符 temp1=re.findall('^morra','nsudi werwuirnmorra') temp2=r ...

  2. usr类库的使用&lpar;一般用在第三方类库使用系统库报错头文件找不到时&rpar;

    第三方Html解析类库Hpple,在导入框架libxml2.2.dylib后,XCode仍然找不到<libxml/tree.h>. 1 .项目 -Targets 中的 Build P ha ...

  3. Objective-C学习笔记之for&lpar; int &rpar;机制

    NSArray *myArray = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4&q ...

  4. js控制html元素的readonly属性

    html元素假设为只读,那么其readonly="readonly",我们现在想通过js来改变readonly属性为可以输入. 初始时,两个输入框都是只读.点击change按钮后, ...

  5. GLSL 中的光照计算

    理论知识转载地址:http://blog.csdn.net/ym19860303/article/details/25545933 1.Lambert模型(漫反射) 环境光: Iambdiff = K ...

  6. 李洪强iOS开发之- 实现简单的弹窗

     李洪强iOS开发之- 实现简单的弹窗 实现的效果:  112222222222223333333333333333

  7. iOS NSInvocation的学习

    用途: NSInvocation的作用和performSelector:withObject:的作用是一样的:用于iOS编程中调用某个对象的消息. performSelector:withObject ...

  8. Oracl 一条sql语句 批量添加、修改数据

    最近一直在用,也一直在学oralc,项目上也用到了批量的添加(读取上传CSV文件信息,把符合条件的信息写入到数据库中),在写的时候想到了可能是数据量大就想该怎么快,(由于本人在.NET开发期间没有做过 ...

  9. 【HDU3595】GG and MM(博弈论)

    [HDU3595]GG and MM(博弈论) 题面 HDU 一个游戏由多个游戏组成,每次每个操作者必须操作所有可以操作的游戏,操作集合为空者输. 每个游戏由两堆石子组成,每次可以从较多的那一堆中取走 ...

  10. java解决手机上传竖拍照片旋转90&bsol;180&bsol;270度问题

    <dependency> <groupId>com.drewnoakes</groupId> <artifactId>metadata-extracto ...