10

They are both CGRects and my program behaves the same when I switch one for the other.

abyx
  • 69,862
  • 18
  • 95
  • 117
George
  • 103
  • 1
  • 4
  • 2
    possible duplicate of [UIView's frame, bounds, center, origin, when to use what?](http://stackoverflow.com/questions/1071112/uiviews-frame-bounds-center-origin-when-to-use-what) – Vladimir Jul 13 '10 at 10:47

3 Answers3

5

See UIView for documentation.

The frame property specifies the origin and size of a view in superview coordinates. The origin of the coordinate system for all views is in the upper-left corner.

The bounds property specifies the origin in the view’s coordinates and its size (the view’s content may be larger than the bounds size).

Community
  • 1
  • 1
willcodejavaforfood
  • 43,223
  • 17
  • 81
  • 111
1

Frame and bounds are similar but frame is in reference to another object (the superview) while bounds references itself.

This question gives lots of great info. You should definitely read it.

One thing I will point out specifically from the other answer is your program will behave the same sometimes. For example, until you rotate the orientation. From the answer by tristan

Running this code:

- (void)viewDidLoad {
    [super viewDidLoad];
    UIWindow *w = [[UIApplication sharedApplication] keyWindow];
    UIView *v = [w.subviews objectAtIndex:0];

    NSLog(@"%@", NSStringFromCGRect(v.frame));
    NSLog(@"%@", NSStringFromCGRect(v.bounds));
}

The output of this code is:

case device orientation is Portrait

{{0, 0}, {768, 1024}} <- frame
{{0, 0}, {768, 1024}} <- bounds

case device orientation is Landscape

{{0, 0}, {768, 1024}} <- frame
{{0, 0}, {1024, 768}} <- bounds

So yes your program will usually behave the same but not in all cases.

Community
  • 1
  • 1
Joshua Dance
  • 8,847
  • 4
  • 67
  • 72
1

please go through this link.Hope this will help you.

  1. http://www.slideshare.net/profmido/05-views
Akshay
  • 425
  • 1
  • 5
  • 16
  • 1
    Note that [link-only answers](http://meta.stackoverflow.com/tags/link-only-answers/info) are discouraged, SO answers should be the end-point of a search for a solution (vs. yet another stopover of references, which tend to get stale over time). Please consider adding a stand-alone synopsis here, keeping the link as a reference. – kleopatra Nov 22 '13 at 09:24