• UIView的层次调整,及子view布局模式自动布局模式(停靠模式)


    UIView*view1=[[UIView alloc]initWithFrame:CGRectMake(10,30,300,30)];

    view1.backgroundColor=[UIColor redColor];
    [self.window addSubview:view1];
    [view1 release];
     
    UIView*view2=[[UIView alloc]init];
    view2.frame=CGRectMake(30,20,50,100);
    view2.backgroundColor=[UIColor blueColor];
    [self.window addSubview:view2];
    [view2 release];
     
    UIView*view3=[[UIView alloc]initWithFrame:CGRectMake(20,50,200,200)];
    view3.backgroundColor=[UIColor yellowColor];
    [self.window addSubview:view3];
    //把某一个view放到最下层
    [self.window sendSubviewToBack:view2];
    //把某一个view放到最上层
    [self.window bringSubviewToFront:view2];
    //把某一个view加入到指定层
    [self.window insertSubview:view2 atIndex:1];
    //把某一个view加入到某层的下面
    [self.window insertSubview:view2 belowSubview:view1];
    //把某一个view加入到某层的上面
    [self.window insertSubview:view2 aboveSubview:view1];
    //交换两个层的view
    [self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
     
    //自动布局模式(停靠模式)
    //前面把_backgroundView设置成了成员变量,为了方便,没有写出来
    _backgroundView=[[UIView alloc]initWithFrame:CGRectMake(110,300,100,100)];
    _backgroundView.background=[UIColor blackColor];
    //设置父view允许子view自动布局
    _backgroundView.autoresizesSubviews=YES;
    [self.window addSubview:_backgroundView];
     
    UIView*topView=[[UIView alloc]initWithFrame:CGRectMake(25,25,50,50)];
    topView.backgroundColor=[UIColor orangeColor];
    //设置子view的自动布局模式
    //下面设置会让topView跟着_backgroundView变化而变化,中心点不变
    topView.autoresizingMask=UIViewAutoresizingFlexibleBottomMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleWidth;
    [_backgroundView addSubview:topView];
    //创建一个按钮,点一下,_backgroundView会变大
    UIButton*btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
    btn.frame=CGRectMake(10,230,300,20);
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    [self.window addSubview:btn];
     
    -(void)click
    {
    _backgroundView.frame=CGRectMake(_backgroundView.frame.origin.x-2,_backgroundView.frame.orgin.y-2,_backgroundView.frame.size.width+4,_backgroundView.frame.height+4);
    }
  • 相关阅读:
    Microsoft 补丁,文档下载
    web_dynpro_Tree1:
    右键的CONTEXT_MENU
    web_dynpro_ALV:(包ZLYTEST2)(alv 的事件只需注意一个R_PARAM就哦了)
    web_dynpro_SELECT_OPTION组件的使用:
    首日签到
    斐波那契数列
    C#正则表达式验证工具
    P210阶段3(个人所得税计算器)
    javascript基本语法
  • 原文地址:https://www.cnblogs.com/youlechang123/p/5724464.html
Copyright © 2020-2023  润新知