视图UIView
1.创建视图的方法
CGRect rect1 = CGRectMake(20, 40, 100, 100);
//创建矩形区域
UIView *redView = [[UIView alloc] initWithFrame:rect1];
//创建视图及初始化
[self.window addSubview:redView];
//将子视图添加到self.window上
[redView setBackgroundColor:[UIColor redColor]];
//给视图添加颜色
[redView release];
//释放内存
2.添加视图的方法:(4种)3个insert 1个add
//添加子视图到self.window上
[self.window addSubview:blueView];
//在某个位置插入子视图
[self.window insertSubview:blueView atIndex:0];
//移到某个视图上面
[self.window insertSubview:blueView aboveSubview:redView];
//移到某个视图下面
[self.window insertSubview:blueView belowSubview:greenView];
bringSubviewToFront: 把指定的子视图移动到最前面
//把红色视图移到最前面
[self.windowbringSubviewToFront:redView];
sendSubviewToBack:把指定的子视图移动到最后面
//把绿色视图移到最后面
[self.windowsendSubviewToBack:greenView];
exchangeSubviewAtIndex:withSubviewAtIndex:交换两个位置的子视图
//把红色和蓝色调换
[self.windowexchangeSubviewAtIndex:1withSubviewAtIndex:2];
[receiver removeFromSuperview]把receiver从父视图上移除
//将红色子视图从父视图上移除
[redViewremoveFromSuperview];
4.属性
hidden, alpha, superview, subview, tag
blueView.hidden = YES;
//隐藏blueView
[blueView setHidden:NO];
//显示blueView
[blueView setAlpha:0.5];
//修改blueView的透明度
NSLog(@"%@", [blueView superview]);
//打印blueView的父视图
NSLog(@"%@", [[blueView superview] superview]);
//Window的父视图为null
NSLog(@"%@", [self.window subviews]);
//打印Window的所有子视图
[greenView setTag:100];
//给greenVIew加一个数字标签100
UIView *aView = [self.window viewWithTag:100];
//通过100这个标签找到一个视图
[aView setBackgroundColor:[UIColor cyanColor]];