//一下为纯代码写的工程,所以先要删掉左侧的 StoryBoard,然后点击左侧最上面那行,就是你的工程刚进来的时候那个页面,删掉 interface Main中的 Main
1 //初始化window,并设置大小
2 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
3 //设置window背景颜色 白色
4 self.window.backgroundColor = [UIColor whiteColor];
5
6 [self.window makeKeyAndVisible];
7 //设置主视图控制器
8 ViewController *rootVier = [[ViewController alloc] init];
9 self.window.rootViewController = rootVier;
10
11 //1.创建UIView对象
12 //初始化aView
13 UIView *aView = [[UIView alloc] init];
14
15 //2.设置AView背景颜色
16 aView.backgroundColor = [UIColor blackColor];
17
18 //3.设置frame 位置和大小
19 aView.frame = CGRectMake(100, 300, 100, 100);
20
21 //4.将aView添加到window视图上
22 [self.window addSubview:aView];
23
24 UIView *aView2 = [[UIView alloc] init];
25 aView2.backgroundColor = [UIColor grayColor];
26 aView2.frame = CGRectMake(200, 300, 100, 100);
27 [self.window addSubview:aView2];
28
29 UIView *aView3 = [[UIView alloc] init];
30 aView3.backgroundColor = [UIColor yellowColor];
31 aView3.frame = CGRectMake(100, 400, 100, 100);
32 [self.window addSubview:aView3];
33
34 UIView *aView4 = [[UIView alloc] init];
35 aView4.backgroundColor = [UIColor redColor];
36 aView4.frame = CGRectMake(200, 400, 100, 100);
37 [self.window addSubview:aView4];
38
39 UIView *cView = [[UIView alloc] init];
40 //设置cView的大小和位置
41 cView.frame = CGRectMake(CGRectGetMinX(aView4.frame), CGRectGetMaxY(aView4.frame), CGRectGetWidth(aView4.frame), CGRectGetHeight(aView4.frame));
42 [self.window addSubview:cView];
43
44 UIView *dView = [[UIView alloc] init];
45 dView.backgroundColor = [UIColor yellowColor];
46 dView.frame = CGRectMake(30, 10, 50, 50);
47 [aView addSubview:dView];
48
49 UIView *eView = [[UIView alloc] init];
50 eView.backgroundColor = [UIColor redColor];
51 eView.frame = CGRectMake(25, 25, 50, 50);
52 [aView2 addSubview:eView];