UIView的一般操作 - iOS - UI基础知识总结1

来源:互联网 发布:mysql 开启慢日志 编辑:程序博客网 时间:2024/05/18 18:17
// UIView__________________________________
    
    // 创建四个view__________________________________
    
    // redView
    UIView *redView = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 200, 100)];
    redView.backgroundColor = [UIColor redColor];
    [containerView addSubview:redView];
    [redView release];
    
    // orangeView
    UIView *orangeView = [[UIView alloc]initWithFrame:CGRectMake(80, 80, 200, 100)];
    orangeView.backgroundColor = [UIColor orangeColor];
    [containerView addSubview:orangeView];
    [orangeView release];
    
    // blueView
    UIView *blueView = [[UIView alloc]initWithFrame:CGRectMake(110, 110, 200, 100)];
    blueView.backgroundColor = [UIColor blueColor];
    [containerView addSubview:blueView];
    [blueView release];
    
    // purpleView
    UIView *purpleView = [[UIView alloc]initWithFrame:CGRectMake(140, 140, 200, 100)];
    purpleView.backgroundColor = [UIColor purpleColor];
    [containerView addSubview:purpleView];
    [purpleView release];
    
    // 设置view背景颜色_________________________________
    
    ((UIView *)[[containerView subviews]objectAtIndex:1]).backgroundColor = [UIColor whiteColor];
    
    // 插入一个view__________________________________
    
    UIView *grayView = [[UIView alloc]initWithFrame:CGRectMake(60, 100, 100, 100)];
    grayView.backgroundColor = [UIColor grayColor];
    
    // 在某个位置插入一个view
    [containerView insertSubview:grayView atIndex:1];
    [grayView release];
    
    // 在某个view上面插入一个view
    [containerView insertSubview:grayView aboveSubview:purpleView];
    [grayView release];
    
    // 在某个view下面插入一个view
    [containerView insertSubview:grayView belowSubview:purpleView];
    [grayView release];
    
    // 管理视图层次__________________________________
    
    // 把指定的子视图移到最前面
    [containerView bringSubviewToFront:redView];
    
    // 把指定的子视图移到最后面
    [containerView sendSubviewToBack:orangeView];
    
    // 交换两个字视图的位置
    [containerView exchangeSubviewAtIndex:1 withSubviewAtIndex:2];
    
    // 把某个子视图从父视图中移除
    [redView removeFromSuperview];
    
    // 隐藏某个view__________________________________
    redView.hidden = YES;
    
    // 获取本视图的所有子视图__________________________________
    NSArray *subviews = [containerView subviews];

    NSLog(@"subviews = %@",subviews);
    
    // 获取本视图的父视图__________________________________
    redView.superview.backgroundColor = [UIColor blackColor];
    
    // 对一个view添加tag值(对一个view添加一个标记,一般要大于100)__________________________________
    redView.tag = 111;
    
    // 父视图根据tag值找到对应的子视图__________________________________
    [containerView viewWithTag:111].backgroundColor = [UIColor grayColor];
    
    // 设置view的透明度__________________________________
    orangeView.alpha = 0.4;
    
    // 设置view的拐角半径__________________________________
    redView.layer.cornerRadius = 10;
0 0
原创粉丝点击