UIView *redView=[[UIView alloc]initWithFrame:CGRectMake(100, 100, 50, 50)];
redView.backgroundColor=[UIColor redColor];
[self.view addSubview:redView];
[redView release];
UIView *bluView=[[UIView alloc]initWithFrame:CGRectMake(120, 120, 50, 50)];
bluView.backgroundColor=[UIColor blueColor];
[self.view addSubview:bluView];
[bluView release];
NSLog(@"subviews==%@",[self.view subviews]);
UIView *yellView=[[UIView alloc]initWithFrame:CGRectMake(130, 130, 50, 50)];
yellView.backgroundColor=[UIColor yellowColor];
[self.view addSubview:yellView];
//在0某个位置插入子视图 insertSubview时候会引用计数+1 是系统加的
// [self.view insertSubview:sView atIndex:0];
//在什么什么上面
[self.view insertSubview:yellView aboveSubview:redView];
[yellView release];
//提到最前面
[self.view bringSubviewToFront:yellView];
[yellView removeFromSuperview];//删除对应的VIew
UIView中插入子视图
最新推荐文章于 2020-04-03 20:11:15 发布