//创建一个窗口,设置大小为屏幕大小
self.window =[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
//设置窗口的背景颜色
// UIImage *myImage = [UIImage imageNamed:@"ppp"];
self.window.backgroundColor = [UIColor colorWithRed:0.06 green:0.47 blue:0.48 alpha:0.9];
//使其成为主窗口,且可见
[self.window makeKeyAndVisible];
UIImage *image = [UIImage imageNamed:@"logo.png"];
UIImageView *imageview = [[UIImageView alloc]initWithImage:image];
imageview.frame = CGRectMake(0, 0, 450, 680);
[self.window addSubview:imageview];
[imageview release];
UIImage *qq = [UIImage imageNamed:@"qq.png"];
UIImageView *imageqq = [[UIImageView alloc]initWithImage:qq];
//UIView就是屏幕上的一个矩形区域
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(80, 120, 100, 30)];
view.backgroundColor = [UIColor colorWithRed:0.6 green:0.46 blue:0.2 alpha:1];
[self.window addSubview:view];
UIView *view2 = [[UIView alloc]initWithFrame:CGRectMake(200, 120, 100, 30)];
view2.backgroundColor = [UIColor colorWithRed:0.6 green:0.46 blue:0.2 alpha:1];
[self.window addSubview:view2];
UIView *view3 = [[UIView alloc]initWithFrame:CGRectMake(140, 250, 100, 30)];
view3.backgroundColor = [UIColor colorWithRed:0.6 green:0.46 blue:0.2 alpha:1];
[self.window addSubview:view3];
//一个视图可以有多个子视图,但只有一个父视图,父视图和子视图是相对而言的。
UIView *view4 = [[UIView alloc]initWithFrame:CGRectMake(15, 5, 70, 20)];
view4.backgroundColor = [UIColor blackColor];
[view addSubview:view4];
UIView *view5 = [[UIView alloc]initWithFrame:CGRectMake(15, 5, 70, 20)];
view5.backgroundColor = [UIColor blackColor];
[view2 addSubview:view5];
UIView *view6 = [[UIView alloc]initWithFrame:CGRectMake(170, 200, 20, 20)];
view6.center = CGPointMake(200, 200);//中心点,相对于父视图而言
view6.backgroundColor = [UIColor redColor];
[self.window addSubview:view6];
// UIView *greenV = [[UIView alloc]initWithFrame:CGRectMake(250, 250, 100, 100)];
// greenV.backgroundColor = [UIColor grayColor];
// [self.window addSubview:greenV];
// //bounds的orign默认为(0,0),是相对于当前视图的左上角的距离
// greenV.bounds = CGRectMake(30, 0, 100, 100);
//
//
// UIView *blackV = [[UIView alloc]initWithFrame:CGRectMake(20, 20, 50, 50)];
// blackV.backgroundColor = [UIColor blackColor];
// [self.window addSubview:blackV];
// //将一个视图加入到另一个视图中,greenv兑redv有所有权,redv的引用计数加1,
// [greenV addSubview:blackV];
UIView *view01 = [[UIView alloc]initWithFrame:CGRectMake(100, 400, 100, 100)];
view01.backgroundColor = [UIColor brownColor];
[self.window addSubview:view01];
UIView *view02 = [[UIView alloc]initWithFrame:CGRectMake(120, 410, 100, 100)];
view02.backgroundColor = [UIColor yellowColor];
[self.window addSubview:view02];
UIView *view03 = [[UIView alloc]initWithFrame:CGRectMake(110, 430, 100, 100)];
view03.backgroundColor = [UIColor purpleColor];
// [self.window addSubview:view03];
// [self.window insertSubview:view03 atIndex:3];
[self.window insertSubview:view03 aboveSubview:view01];
// [self.window insertSubview:view03 belowSubview:view01];
UIView *viewWhite = [[UIView alloc]initWithFrame:CGRectMake(130, 450, 100, 100)];
viewWhite.backgroundColor = [UIColor whiteColor];
[self.window insertSubview:viewWhite belowSubview:view03];
[self.window bringSubviewToFront:imageview];
[self.window sendSubviewToBack:imageview];
[self.window exchangeSubviewAtIndex:7 withSubviewAtIndex:9];
// 从父视图中移除
// [viewWhite removeFromSuperview];
NSArray *arr = [self.window subviews];
NSLog(@"%ld",[arr count]);
viewWhite.alpha = 0.5;
view03.alpha = 0.5;
view02.alpha = 0.5;
view01.alpha = 0.5;
viewWhite.tag = 10;
UIView *copyView = [self.window viewWithTag:10];
[self.window insertSubview:copyView belowSubview:view01];
copyView.backgroundColor = [UIColor orangeColor];
UIView *view001 = [[UIView alloc]initWithFrame:CGRectMake(0, 300, 50, 100)];
view001.backgroundColor = [UIColor redColor];
UIView *view002 = [[UIView alloc]initWithFrame:CGRectMake(50, 300, 50, 100)];
view002.backgroundColor = [UIColor greenColor];
UIView *view003 = [[UIView alloc]initWithFrame:CGRectMake(100, 300, 50, 100)];
view003.backgroundColor = [UIColor blueColor];
UIView *view004 = [[UIView alloc]initWithFrame:CGRectMake(150, 300, 50, 100)];
view004.backgroundColor = [UIColor cyanColor];
UIView *view005 = [[UIView alloc]initWithFrame:CGRectMake(200, 300, 50, 100)];
view005.backgroundColor = [UIColor yellowColor];
UIView *view006 = [[UIView alloc]initWithFrame:CGRectMake(250, 300, 50, 100)];
view006.backgroundColor = [UIColor magentaColor];
UIView *view007 = [[UIView alloc]initWithFrame:CGRectMake(300, 300, 50, 100)];
view007.backgroundColor = [UIColor orangeColor];
UIView *view008 = [[UIView alloc]initWithFrame:CGRectMake(350, 300, 50, 100)];
view008.backgroundColor = [UIColor purpleColor];
imageqq.frame = CGRectMake(80, 200, 50, 50);
imageqq.backgroundColor = [UIColor clearColor];
// NSArray *array = [[NSArray alloc]initWithObjects:view001,view002,view003,view004,view005,view006,view007, nil];
[self.window addSubview:view007];
[self.window addSubview:view006];
[self.window addSubview:view005];
[self.window addSubview:view004];
[self.window addSubview:view003];
[self.window addSubview:view002];
[self.window addSubview:view001];
[self.window addSubview:view008];
[self.window addSubview:imageqq];
[imageqq release];
[view008 release];
[view007 release];
[view006 release];
[view005 release];
[view004 release];
[view003 release];
[view002 release];
[view001 release];
[viewWhite release];
[view03 release];
[view02 release];
[view01 release];