我先加载图片,
1. 2.
3. 4..
5. 6.
7.8.
代码如下:
- (void)viewDidLoad
{
[super viewDidLoad];
UIView *yellowView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
yellowView.backgroundColor = [UIColor yellowColor];
UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 100, 100)];
redView.backgroundColor = [UIColor redColor];
UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(80, 80, 100, 100)];
blueView.backgroundColor = [UIColor blueColor];
[self.view addSubview:yellowView];
[self.view addSubview:redView];
[self.view addSubview:blueView];
//1
//------
UIView *blackView = [[UIView alloc]initWithFrame:CGRectMake(80, 80, 200, 200)];
[blackView setBackgroundColor:[UIColor blackColor]];
[self.view insertSubview:blackView atIndex:1];
//2
//-------
UIView *orangeView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 300)];
[orangeView setBackgroundColor:[UIColor orangeColor]];
[self.view insertSubview:orangeView aboveSubview:yellowView];
//3
//------
UIView *greenView = [[UIView alloc]initWithFrame:CGRectMake(30, 30, 320, 480)];
[greenView setBackgroundColor:[UIColor greenColor]];
[self.view insertSubview:greenView belowSubview:yellowView];
//4
//-------
//绿色和 黑色交换
[self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:3];
//你已经看不到黑色的了5
//------
[self.view bringSubviewToFront:redView];//
//6
//----------
//绿色的向后
[self.view sendSubviewToBack:greenView];
//7
//--------------
//移除绿色的
[greenView removeFromSuperview];
//8
//--------
[yellowView release];
[redView release];
[blueView release];
[blackView release];
[orangeView release];
[greenView release];
// Do any additional setup after loading the view, typically from a nib.
}