iOS学习、交流、进步

子视图的插入、删除

- (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];
}

阅读更多
文章标签: ios 子视图
个人分类: ios学习笔记
上一篇IOS视图切换实现简单动画
下一篇ios在视图上设置按钮
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭