您的位置:首页 > 产品设计 > UI/UE

iOS入门(二十四)UIView

2015-08-11 16:41 375 查看
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];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: