UIView的属性使用

  

   在此之前我先简单的说一下frame 和bounds 的区别:frame 是该视图在父视图的位置,所谓的父视图就是我们在创建视图时将它添加显示在哪个视图上, bounds是该视图在自己视图上的位置 

      center 这个是中心点的位置 是CGPoint 类型

    //视图的frame是依赖于父视图产生的坐标系统来确定其起始点和大小的

    //视图的bounds是依赖于自身产生的坐标系统的,默认起始点的值为0,0与坐标系远点重合,sizeframe指定的size一致.一旦修改了一个视图的bounds,不会影响视图的位置(frame不变)但是会让自身产生的坐标系统偏移,导致添加在其上的子视图产生相对位置的变化

    //视图的framecenter共同参考父视图产生的坐标系.frameorigin(起始点)发生改变,size(大小)发生改变都会影响center (中心点) 的位置 .center的修改只会影响frameorigin.

   

    NSLog(@"%@",NSStringFromCGRect(self.window.frame));

    NSLog(@"%@",NSStringFromCGRect(yellowView.frame));

          NSLog(@"%@",NSStringFromCGRect(yellowView.bounds));


  

   

   //创建aView,设置frame

   UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 200, 200)]

    ;

    //改变背景颜色

    aView.backgroundColor = [UIColor whiteColor];

    //改变四角,就是四个角的内切圆半径,使视图四角由直角变为圆角 

    aView.layer.cornerRadius = 20;

    //改变线框的颜色

    aView.layer.borderColor = [[UIColor blackColor]CGColor];

    //改变线框的粗细,这里的数字 单位是像素点

    aView.layer.borderWidth = 2;

    //加入到window视图上,window则是这个视图的父视图

    [self.window addSubview:aView];

    [aView release];

   

    UIView *bView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 150)]

    ;

    bView.backgroundColor = [UIColor redColor];

    bView.layer.cornerRadius = 20;

    bView.layer.borderColor = [[UIColor blackColor]CGColor];

    bView.layer.borderWidth = 1;

    //这个是让该视图的中心点等于第一个视图的中心点

    bView.center = aView.center;

    [self.window addSubview:bView];

    [bView release];

    

    UIView *cView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]

    ;

    cView.backgroundColor = [UIColor orangeColor];

    cView.center = bView.center;

    cView.layer.cornerRadius = 20;

    cView.layer.borderColor = [[UIColor blackColor]CGColor];

    cView.layer.borderWidth = 2;

    [self.window addSubview:cView];

    [cView release];

    

    //window aView视图放在cView

    [self.window insertSubview:aView aboveSubview:cView];

    //window aview视图放在bview

    [self.window insertSubview:aView belowSubview:bView];

    //bview视图放在下标为2的位置上

    [self.window insertSubview:bView atIndex:2];

    //cview放在最前面

    [self.window bringSubviewToFront:cView];

    //bview放在最下面

    [self.window sendSubviewToBack:bView];

    //交换 下标为0,2的俩个视图位置

    [self.window exchangeSubviewAtIndex:0 withSubviewAtIndex:2];

    //aview视图 移除他所在的父视图

    [aView removeFromSuperview];

    NSLog(@"%@",NSStringFromCGRect(bView.frame));

    NSLog(@"%@",NSStringFromCGRect(bView.bounds));

   //显隐 hidden YES视图消失,当为NO显示. 系统默认为NO;

    cView.hidden = YES;

    //标记 视图

    bView.tag = 1000 ;

    //取出视图

    [self.window viewWithTag:1000];

    //取出其子视图

     NSArray *array1 = [self.window subviews];

    //取出其父视图

     NSArray *array2 = [bView superview];

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值