frame其实也是一个结构体,是结构体CGRect的一个变量。两个成员变量里分别有两个成员变量都是cgfloat类型的。
UIView * view2 = [[UIView alloc]initWithFrame:CGRectMake(0, 45, 50, 50)];
view2.backgroundColor = [UIColor blueColor];
[view addSubview:view2];
[view2 release];
UIView * view3 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 20, 10)];
view3.backgroundColor = [UIColor yellowColor];
[view2 addSubview:view3];
[view3 release];
// 将视图插在指定的层数上
//index数值 越小越靠后 0开始
UIView * greenView = [[UIView alloc]initWithFrame:CGRectMake(60, 50, 50, 100)];
greenView.backgroundColor = [UIColor greenColor];
[self.window insertSubview:greenView atIndex:1];
// 将第一个参数的视图 插入到第二个参数视图的后面
[self.window insertSubview:RedView belowSubview:greenView];
// 第一个参数视图 放到 第二个参数视图的上面
[self.window insertSubview:greenView aboveSubview:RedView];
// 将指定视图移动到最前面
[self.window bringSubviewToFront:RedView];
// 将指定视图移动到最后面
[self.window sendSubviewToBack:RedView];
// 将指定视图交换
[self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
// 将视图隐藏
blueView.hidden=YES;
// 调整视图的透明度
RedView.alpha=0.5;
[greenView release];
//获取本视图的父视图
UIView * test = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];
[blueView addSubview:test];
test.backgroundColor = [UIColor cyanColor];
UIView * resu = [test superview];
resu.backgroundColor = [UIColor blackColor];
//获取本视图的子视图
NSArray * subview = [blueView subviews];
UIView * vie1 = subview[0];
vie1.backgroundColor = [UIColor whiteColor];
//给视图添加了标记 被添加完标记的视图 可以使用 viewWithTag 方法取出 数要大于100
blueView.tag=101;
UIView * vi =[self.window viewWithTag:101];
vi.backgroundColor = [UIColor yellowColor];
// 设置view 的圆角
blueView.layer.masksToBounds=YES;
// 每个角弯曲的半径是多少 方形才有可能变成圆圈
blueView.layer.cornerRadius=75;
//bounds
在每添加一个view的时候,每个view分别以自己的起点为(0,0)点,创建一个坐标系,这个bounds就是一个结构体,用来确定view的新坐标。
// bounds也是结构体,与frame一样。只是坐标是从自己的原点开始。
// 当视图创建之后,会产生自己的一套坐标系。给自己的子视图用。起点也是左上角开始。
frame与bounds的区别:
frame与bounds都是结构体,都是用来确定位置和大小的;
frame的位置是从屏幕的最左上角开始算的;
bounds是从新添加的view的最左上角的点开始算