//建立一个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];
//根据中心点重新设置矩形的位置
// 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];