[课堂实践与项目]多视图的层次 框架 子视图之间的切换

我先加载图片,

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.
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值