iOS入门(二十四)UIView
2015-08-11 16:41
393 查看
UIView
第一类:互联网两大核心技术 : 即时通讯 视频
第二类:面向对象不同(市场细分): eg :面向女性的应用
第三类:新闻类
音频
团购(用户体验,信息罗列)
购物
阅读
地图
目前移动互联网最暴利:手机游戏
command + 1 最大 +2 正常 +3 最小
3.5寸屏 物理尺寸 :320*480 像素尺寸: 640*960
4寸屏 320*568
UIView的层级关系
frame 相对于父视图定义自己的位置
bounds 改变自己的位置关系(现在的原点相对于新的坐标系来说)改变尺寸大小时,保持中心点不变(不改变它的位置)
center 相对于父视图 确定中心点位置
//建立一个UIWindow的对象, 并让它和屏幕一样大。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//设置window的背景颜色
self.window.backgroundColor = [UIColor darkGrayColor];
//如何创建UIView
//CGRect 规定了一个矩形的位置和大小
CGRect rect = {{10,20},{300,300}};
UIView * view1 = [[UIView alloc]initWithFrame:rect];
//把view贴到window上
[self.window addSubview:view1];
[view1 setBackgroundColor : [UIColor blackColor] ];
[view1 release];
CGRect rect2 = CGRectMake(10, 10, 280, 280);
UIView * view2 = [[UIView alloc]initWithFrame:rect2];
view2.backgroundColor = [UIColor blueColor];
[view1 addSubview:view2];
[view2 release];
//设置为主window并且可见
[self.window makeKeyAndVisible];
//根据中心点重新设置矩形的位置
// view2.center = CGPointMake(100, 100);
// view2.bounds = CGRectMake(20, 20, 250, 250);
UIView * view3 = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 250, 250)];
[_window addSubview:view3];
view3.backgroundColor = [UIColor purpleColor];
[view3 release];
UIView * view4 = [[UIView alloc]initWithFrame:CGRectMake(200, 200, 200, 250)];
view4.backgroundColor = [UIColor blueColor];
// [view1 insertSubview:view4 atIndex:0];
// [view1 insertSubview:view4 belowSubview:view2];
[_window addSubview:view4];
[view4 release];
[_window sendSubviewToBack:view1];
view4.hidden = NO;
view3.alpha = 0.5;
UIView * view5 = [view4 superview];
view5.backgroundColor = [UIColor brownColor];
[view5 release];
NSArray * views = [_window subviews];
UIView * view6 = [views objectAtIndex:1];
view6.backgroundColor = [UIColor cyanColor];
// view6.center = CGPointMake(150, 150);
UIView * view7 = [view4.superview.subviews firstObject];
view7.backgroundColor = [UIColor blackColor];
view1.tag = 100;
[[_window viewWithTag:100] setBackgroundColor:[UIColor greenColor]];
UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 50, 20)];
label1.backgroundColor = [UIColor blackColor];
[_window addSubview:label1];
// UIView * aview = [[UIView alloc]initWithFrame:CGRectMake(20, 40, 120, 240)];
// aview.backgroundColor = [UIColor yellowColor];
// [_window addSubview:aview];
// [aview release];
// UIView * bview = [[UIView alloc]initWithFrame:CGRectMake(40, 60, 120, 240)];
// bview.backgroundColor = [UIColor greenColor];
// [_window addSubview:bview];
// [bview release];
// UIView * cview = [[UIView alloc]initWithFrame:CGRectMake(60, 80, 120, 240)];
// cview.backgroundColor = [UIColor brownColor];
// [_window insertSubview:cview atIndex:1];
// [cview release];
// UIView * dview = [[UIView alloc]initWithFrame:CGRectMake(80, 100, 120, 240)];
// dview.backgroundColor = [UIColor blueColor];
// [_window insertSubview:dview aboveSubview:aview];
// [dview release];
// UIView * eview = [[UIView alloc]initWithFrame:CGRectMake(100, 120, 120, 240)];
// eview.backgroundColor = [UIColor magentaColor];
// [_window insertSubview:eview belowSubview:bview];
// [eview release];
[_window bringSubviewToFront:aview];
[_window sendSubviewToBack:bview];
[_window exchangeSubviewAtIndex:3 withSubviewAtIndex:4];
[dview removeFromSuperview];
第一类:互联网两大核心技术 : 即时通讯 视频
第二类:面向对象不同(市场细分): eg :面向女性的应用
第三类:新闻类
音频
团购(用户体验,信息罗列)
购物
阅读
地图
目前移动互联网最暴利:手机游戏
command + 1 最大 +2 正常 +3 最小
3.5寸屏 物理尺寸 :320*480 像素尺寸: 640*960
4寸屏 320*568
UIView的层级关系
frame 相对于父视图定义自己的位置
bounds 改变自己的位置关系(现在的原点相对于新的坐标系来说)改变尺寸大小时,保持中心点不变(不改变它的位置)
center 相对于父视图 确定中心点位置
//建立一个UIWindow的对象, 并让它和屏幕一样大。
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
//设置window的背景颜色
self.window.backgroundColor = [UIColor darkGrayColor];
//如何创建UIView
//CGRect 规定了一个矩形的位置和大小
CGRect rect = {{10,20},{300,300}};
UIView * view1 = [[UIView alloc]initWithFrame:rect];
//把view贴到window上
[self.window addSubview:view1];
[view1 setBackgroundColor : [UIColor blackColor] ];
[view1 release];
CGRect rect2 = CGRectMake(10, 10, 280, 280);
UIView * view2 = [[UIView alloc]initWithFrame:rect2];
view2.backgroundColor = [UIColor blueColor];
[view1 addSubview:view2];
[view2 release];
//设置为主window并且可见
[self.window makeKeyAndVisible];
//根据中心点重新设置矩形的位置
// view2.center = CGPointMake(100, 100);
// view2.bounds = CGRectMake(20, 20, 250, 250);
UIView * view3 = [[UIView alloc] initWithFrame:CGRectMake(150, 150, 250, 250)];
[_window addSubview:view3];
view3.backgroundColor = [UIColor purpleColor];
[view3 release];
UIView * view4 = [[UIView alloc]initWithFrame:CGRectMake(200, 200, 200, 250)];
view4.backgroundColor = [UIColor blueColor];
// [view1 insertSubview:view4 atIndex:0];
// [view1 insertSubview:view4 belowSubview:view2];
[_window addSubview:view4];
[view4 release];
[_window sendSubviewToBack:view1];
view4.hidden = NO;
view3.alpha = 0.5;
UIView * view5 = [view4 superview];
view5.backgroundColor = [UIColor brownColor];
[view5 release];
NSArray * views = [_window subviews];
UIView * view6 = [views objectAtIndex:1];
view6.backgroundColor = [UIColor cyanColor];
// view6.center = CGPointMake(150, 150);
UIView * view7 = [view4.superview.subviews firstObject];
view7.backgroundColor = [UIColor blackColor];
view1.tag = 100;
[[_window viewWithTag:100] setBackgroundColor:[UIColor greenColor]];
UILabel * label1 = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 50, 20)];
label1.backgroundColor = [UIColor blackColor];
[_window addSubview:label1];
// UIView * aview = [[UIView alloc]initWithFrame:CGRectMake(20, 40, 120, 240)];
// aview.backgroundColor = [UIColor yellowColor];
// [_window addSubview:aview];
// [aview release];
// UIView * bview = [[UIView alloc]initWithFrame:CGRectMake(40, 60, 120, 240)];
// bview.backgroundColor = [UIColor greenColor];
// [_window addSubview:bview];
// [bview release];
// UIView * cview = [[UIView alloc]initWithFrame:CGRectMake(60, 80, 120, 240)];
// cview.backgroundColor = [UIColor brownColor];
// [_window insertSubview:cview atIndex:1];
// [cview release];
// UIView * dview = [[UIView alloc]initWithFrame:CGRectMake(80, 100, 120, 240)];
// dview.backgroundColor = [UIColor blueColor];
// [_window insertSubview:dview aboveSubview:aview];
// [dview release];
// UIView * eview = [[UIView alloc]initWithFrame:CGRectMake(100, 120, 120, 240)];
// eview.backgroundColor = [UIColor magentaColor];
// [_window insertSubview:eview belowSubview:bview];
// [eview release];
[_window bringSubviewToFront:aview];
[_window sendSubviewToBack:bview];
[_window exchangeSubviewAtIndex:3 withSubviewAtIndex:4];
[dview removeFromSuperview];
相关文章推荐
- Version和Build的区别
- UIScrollView
- hdoj-1242-Rescue【广搜+优先队列】
- UIImageVIew
- UIButton&UILabel
- IOS第八天(4:UITableViewController新浪微博, 代码创建布局和数据转模型)
- UI初识
- Easyui 表格datagrid 的单元格内容显示方式扩展
- Easy UI的树形菜单的异步加载
- FlexBuilder远程调试WEB应用
- 控件学习---UIPageControl---摘自培训资料
- Halton Sequence 原理和代码实现
- 23-IO流-51-IO流(序列流-SequenceInputStream-枚举和迭代)
- 23-IO流-50-IO流(序列流-SequenceInputStream)
- UIScrollView或者UITableView 点击状态栏,回不到顶部的解决办法
- Druid数据库连接池的简单使用
- poj 3715 Blue and Red(二分图最大匹配+字典序输出)
- iOS基础-UIKit框架-高级视图-UIPickerView-实例2:城市选择(列与列之间有关系)
- Map四种获取key和value值的方法,以及对map中的元素排序
- 让JPA的Query返回Map对象