标签:
1 #import "AppDelegate.h" 2 3 // 创建UIWindow对象 4 /** 5 自动创建 6 程序运行从main()函数开始执行UIApplicationMain创建代理,然后加载配置文件Info.plist()(Main Interface设置了程序的主入口),根据name找到对应的storyboard,加载storyboard,storyboard会自动创建一个UIWindow对象 7 */ 8 9 /* 10 屏幕大小 11 iPhone4(s) : 320 * 480 12 iPhone5(s) : 320 * 568 13 iPhone6(s) : 375 * 667 14 iPhone6(s) Plus : 414 * 736 15 */ 16 17 18 @interface AppDelegate () 19 20 @end 21 22 @implementation AppDelegate 23 24 25 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 26 // 手动创建(首先关闭Main Interface) 27 28 // 1.创建对象并设置为屏幕大小 29 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 30 31 // 2.为Window设置颜色 32 self.window.backgroundColor = [UIColor whiteColor]; 33 34 // 3.将window对象显示出来 35 [self.window makeKeyAndVisible]; // 将这个窗口设置为主窗口并显示 36 37 // 4.为window设置根视图控制器 38 self.window.rootViewController = [[ViewController alloc] init]; 39 40 41 /* 42 UIView(表示一块矩形的区域) 43 几乎所有可视化的视图都是UIView的子类 44 */ 45 // 1.创建UIView对象(分配存储空间,设置位置和大小) 46 CGFloat x = 100; 47 CGFloat y = 100; 48 CGFloat w = 200; 49 CGFloat h = 200; 50 51 UIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)]; 52 53 // 2.设置view的属性 54 view1.backgroundColor = [UIColor redColor]; 55 56 // 3.将创建的view添加到window上 57 [self.window addSubview:view1]; 58 59 60 /* 61 子视图和父视图 62 使用addSubview:添加视图,要确定谁添加到谁上面,被添加的是子视图,添加到的视图是父视图 63 */ 64 65 66 // UIView常见的属性 67 // center 中心点 68 view1.center = self.window.center; 69 70 // alpha 透明度(0~1) 71 view1.alpha = 0.5; 72 73 // hidden 隐藏 74 view1.hidden = NO; 75 76 // superView 77 NSLog(@"%@", view1.superview); 78 79 // subViews 80 NSLog(@"%@", self.window.subviews); 81 82 // tag 83 view1.tag = 100; 84 85 // 通过tag值查找view(在父视图上查找) 86 UIView *tagView = [self.window viewWithTag:100]; 87 tagView.backgroundColor = [UIColor purpleColor]; 88 89 90 // 视图的层次关系 91 // 往view上添加视图是一张一张覆盖上去的,是有层次关系的 92 UIView *aView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds]; 93 aView.backgroundColor = [UIColor blueColor]; 94 [self.window addSubview:aView]; 95 96 UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]; 97 bView.backgroundColor = [UIColor orangeColor]; 98 [aView addSubview:bView]; 99 100 UIView *cView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; 101 cView.backgroundColor = [UIColor yellowColor]; 102 [bView addSubview:cView]; 103 104 105 // 通过指定层次下标来添加视图 106 UIView *dView = [[UIView alloc] initWithFrame:CGRectMake(20, 20, 100, 100)]; 107 dView.backgroundColor = [UIColor greenColor]; 108 //[bView addSubview:dView]; 109 110 // 同一个父视图上,指定位置插入子视图 111 [bView insertSubview:dView atIndex:0]; 112 //[bView insertSubview:dView belowSubview:cView]; 113 114 // 同一个父视图上,将一个视图添加到另一个视图的上面 115 UIView *eView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 100, 100)]; 116 eView.backgroundColor = [UIColor redColor]; 117 [bView insertSubview:eView aboveSubview:dView]; 118 119 // 同一个父视图上,将一个视图添加到另一个视图的下面 120 [bView insertSubview:cView belowSubview:eView]; 121 122 123 // 修改视图的层次关系 124 125 // 把指定的子视图移动到最前面 126 [bView bringSubviewToFront:dView]; 127 128 // 把指定的子视图移动到最后面 129 [bView sendSubviewToBack:dView]; 130 131 // 交换两个指定索引位置的子视图 132 [bView exchangeSubviewAtIndex:0 withSubviewAtIndex:2]; 133 134 // 把子视图从父视图中移除 135 [dView removeFromSuperview]; 136 137 138 return YES; 139 } 140 141 @end
标签:
原文地址:http://www.cnblogs.com/zhizunbao/p/5356354.html