zoukankan      html  css  js  c++  java
  • What's the Difference between the frame and the bounds?

    The bounds of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to its own coordinate system (0,0).

    The frame of an UIView is the rectangle, expressed as a location (x,y) and size (width,height) relative to the superview it is contained within.

    So, imagine a view that has a size of 100x100 (width x height) positioned at 25,25 (x,y) of its superview. The following code prints out this view's bounds and frame:

    // This method is in the view controller of the superview
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        NSLog(@"bounds.origin.x: %f", label.bounds.origin.x);
        NSLog(@"bounds.origin.y: %f", label.bounds.origin.y);
        NSLog(@"bounds.size. %f", label.bounds.size.width);
        NSLog(@"bounds.size.height: %f", label.bounds.size.height);
    
        NSLog(@"frame.origin.x: %f", label.frame.origin.x);
        NSLog(@"frame.origin.y: %f", label.frame.origin.y);
        NSLog(@"frame.size. %f", label.frame.size.width);
        NSLog(@"frame.size.height: %f", label.frame.size.height);
    }
    

    And the output of this code is:

    bounds.origin.x: 0
    bounds.origin.y: 0
    bounds.size. 100
    bounds.size.height: 100
    
    frame.origin.x: 25
    frame.origin.y: 25
    frame.size. 100
    frame.size.height: 100
    


    签名:删除冗余的代码最开心,找不到删除的代码最痛苦!
  • 相关阅读:
    codeforces 349B Color the Fence 贪心,思维
    luogu_2022 有趣的数
    luogu_2320 [HNOI2006]鬼谷子的钱袋
    luogu_1879 [USACO06NOV]玉米田Corn Fields
    SAC E#1
    luogu_1984 [SDOI2008]烧水问题
    luogu_2085 最小函数值
    luogu_1631 序列合并
    luogu_1196 银河英雄传说
    luogu_1037 产生数
  • 原文地址:https://www.cnblogs.com/season2009/p/2530040.html
Copyright © 2011-2022 走看看