子视图的插入、删除
来源:互联网 发布:淘宝店铺服务态度 编辑:程序博客网 时间:2024/06/05 14:28
- (void)viewDidLoad{ [super viewDidLoad]; //创建一个UIView作为一个子视图,添加到父视图中 UIView * pView1 = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 150, 150)]; pView1.backgroundColor = [UIColor redColor]; [self.view addSubview:pView1]; //创建第二个子视图 UIView * pView2 = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 200, 200)]; pView2.backgroundColor = [UIColor blueColor]; [self.view addSubview:pView2]; //创建第三个子视图 UIView * pView3 = [[UIView alloc]initWithFrame:CGRectMake(100, 100, 250, 250)]; pView3.backgroundColor = [UIColor yellowColor]; [self.view addSubview:pView3]; //添加子视图 [self.view insertSubview:pView1 aboveSubview:pView3]; [self.view insertSubview:pView3 atIndex:0]; [self.view insertSubview:pView3 belowSubview:pView2]; //重新排序子视图 [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1]; [self.view sendSubviewToBack:pView3]; [self.view bringSubviewToFront:pView1]; //删除子视图 [self.view removeFromSuperview];}