博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
What's the Difference between the frame and the bounds?
阅读量:5319 次
发布时间:2019-06-14

本文共 1256 字,大约阅读时间需要 4 分钟。

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

The frame of an  is the , 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.width: %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.width: %f", label.frame.size.width);    NSLog(@"frame.size.height: %f", label.frame.size.height);}

And the output of this code is:

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

 

转载于:https://www.cnblogs.com/season2009/archive/2012/06/01/2530040.html

你可能感兴趣的文章