frame 和 bounds 区别

- (void)creatViews {
    //frame 坐标都是 相对于父视图坐标系的坐标
    UIView *redView = [[UIView alloc] initWithFrame:CGRectMake(30, 50, 200, 100)];
    //设置背景颜色
    redView.backgroundColor = [UIColor redColor];
    
    UIView *blueView = [[UIView alloc] initWithFrame:CGRectMake(10, 10, 50, 50)];
    blueView.backgroundColor = [UIColor blueColor];
    //frame 都是相对于父视图的
    //获取视图的边框 前两项默认是 0 0
    CGRect bounds = redView.bounds;
    //把一个结构体转化为字符串打印
    NSLog(@"%@",NSStringFromCGRect(bounds));
    //{{0, 0}, {200, 100}}
    //redView.bounds = CGRectMake(0, 0, 200, 100);
    //我们一般使用bounds 来获取/修改视图的大小 前两项一般都是0
    /*
     确定一个视图的大小和位置 可以用frame 或者 bounds+center
     
     bounds 和 frame的区别
     1.frame 是相对于 父视图坐标系的坐标
       bounds 是相对于自己坐标系的坐标
     2.bounds 一般 就是前两项 0 0,一旦修改那么当前视图的自己的坐标系的位置就会改变,这样会影响当前视图子视图的位置
     
     */
    
 
    //确定父子视图
    [redView addSubview:blueView];
    [blueView release];

    [self.window addSubview:redView];
    [redView release];

}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值