关闭

子视图的插入、删除

标签: ios子视图
1127人阅读 评论(0) 收藏 举报
分类:
- (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];
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:58243次
    • 积分:1126
    • 等级:
    • 排名:千里之外
    • 原创:55篇
    • 转载:3篇
    • 译文:0篇
    • 评论:11条
    最新评论