标签:
1、frame、center是相当于父视图而言的,改变视图本身的frame、center会直接影响自身在其父视图上的显示位置。
// 画纸
UIView *containerView = [[UIView alloc] initWithFrame:self.window.bounds];
containerView.backgroundColor = [UIColor whiteColor];
[self.window addSubview:containerView];
[containerView release];
UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(100, 200, 200, 200)];
blueView.backgroundColor = [UIColor blueColor];
// 设置中心点的位置
blueView.center = self.window.center;
// 设置不透明度为50%
blueView.alpha = 0.5;
// 给蓝色视图添加一个标记
blueView.tag = 101;
[containerView addSubview:blueView];
// 获取蓝色视图的父视图
NSLog(@"superview is %@ containerView is %@",blueView.superview, containerView);
NSLog(@"subviews is %@ blueView is %@",containerView.subviews, blueView);
// 通过tag找到blueView并且将其颜色改为红色
[containerView viewWithTag:101].backgroundColor = [UIColor redColor];
[blueView release];
UIView *yellowView = [[UIView alloc] initWithFrame:CGRectMake(200, 200, 100, 100)];
yellowView.backgroundColor = [UIColor yellowColor];
// 在某一个下标下让父视图插入一个新的子视图
[containerView insertSubview:yellowView atIndex:1];
[yellowView release];
// 移除试图,把某一个视图从父视图中移除
[blueView removeFromSuperview];
标签:
原文地址:http://www.cnblogs.com/lovecx/p/5169469.html