UI01_UIView

来源:互联网 发布:微信弹幕软件 编辑:程序博客网 时间:2024/05/04 07:42
//========================================>//xcode4,5--> xcode6 取消了空模板//xcode6-->xcode7 必须指定根视图控制器//========================================self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];// Override point for customization after application launch.self.window.backgroundColor = [UIColor greenColor];[self.window makeKeyAndVisible];//窗子可视ViewController *vi = [[ViewController alloc] init];self.window.rootViewController = vi;//========================================>//*==============老师的=============*//uiview//初始化viewUIView *view1 = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];//给view添加背景颜色view1.backgroundColor = [UIColor redColor];//添加到window上[self.window addSubview:view1];//常用属性//1中心

// view1.center = self.window.center;
//2透明度 0-1
view1.alpha = 1;
//3是否隐藏
view1.hidden = NO;
//4查看父视图
NSLog(@”%@”,[view1 superview]);
//5查看子视图
NSLog(@”%@”,[self.window subviews]);
//6标记tag
view1.tag = 100;
//通过标记找到对应的视图
UIView *resultView = [self.window viewWithTag:100];
resultView.backgroundColor = [UIColor blackColor];

/* 创建UIView对象: 1. 设置frame x = 100,y = 200 ,w = 100 ,h = 100 2. 设置背景色为蓝色 3. 添加到window上 4. 把view放到屏幕中心位置 5. 设置透明度50% 6. 打印它的父视图 7. 打印它的子视图 8. 通过tag值把背景色改为红色 *//*=============================练习UIView *vieww = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 100, 100)];vieww.backgroundColor = [UIColor blueColor];[self.window addSubview:vieww];vieww.center = self.window.center;vieww.alpha = 0.5;NSLog(@"%@",[vieww superview]);NSLog(@"%@",[self.window subviews]);vieww.tag = 5;UIView *resultw = [self.window viewWithTag:5];resultw.backgroundColor = [UIColor redColor];*/UIView *view2 = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];view2.backgroundColor = [UIColor orangeColor];[self.window insertSubview:view2 atIndex:1];UIView *view3 = [[UIView alloc] initWithFrame:CGRectMake(60, 60, 100, 100)];view3.backgroundColor = [UIColor blueColor];//在某个视图上面插入一个视图//[self.window insertSubview:view3 aboveSubview:view2];//在某一个视图下面插入一个视图[self.window insertSubview:view3 belowSubview:view2];//将某个视图移到最上面[self.window bringSubviewToFront:view3];//将某个视图移到下面[self.window sendSubviewToBack:view3];//子视图(自杀)  从父视图中移除[view3 removeFromSuperview];//创建一个Button/* 控件自己有初始化方法就用自己的 没有就用父类的 第一条属性上面的第一个方法就是控件自己的初始化方法 */UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];//指定位置大小button1.frame = CGRectMake(200, 500, 100, 45);//背景色button1.backgroundColor = [UIColor brownColor];//设置文字[button1 setTitle:@"确定" forState:UIControlStateNormal];button1.showsTouchWhenHighlighted = YES;//加到window窗户上[self.window addSubview:button1];//========================================
0 0
原创粉丝点击