33

Let me try to explain it. Please tell me if I am wrong. I am just 70% sure about it.

Like I understand it, an UIView has a frame and an bounds rectangle. The job of the frame rectangle is to set the position of the UIView relative to it's superview. More precisely: Relative to the coordinate system of the superview. The job of the bounds rectangle is to set the drawing area of the UIView, relative to it's own coordinate system.

Briefly:

  • frame rectangle is for positioning the UIView relative to its superview
  • bounds rectangle is to set the drawing area of the UIView

Are there any mistakes or important things I missed?

Thanks
  • 40,109
  • 71
  • 208
  • 322

5 Answers5

39

Check out Apple's guide on View Geometry. They have pretty good examples on what happens when you change bounds and frame values.

Maxim Veksler
  • 29,272
  • 38
  • 131
  • 151
calebt
  • 850
  • 7
  • 10
  • 1
    Thanks! Very good one. Seems like a lot of that mac documentation stuff applies also to the iPhone. Pretty scary though, how much stuff is there to read ;) – Thanks Apr 21 '09 at 14:52
  • Thanks for the link @calebt. Unfortunately I now have to read it. – Dan Rosenstark Jul 12 '10 at 23:24
  • welcome to stackoverflow! The rule around here is to include the answer, not just link to it. – Jonny May 29 '15 at 00:20
  • Can't believe this answer got about 40 upvotes. Link in the answer is not for UIKit. Correct link is here: https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/ViewPG_iPhoneOS/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40009503-CH2-SW6 – erkanyildiz Jun 17 '15 at 21:17
9

A view's Frame: the position and size of a rectangle inside the superview where the view will fill.

A view's Bound: the position and size of a rectangle inside the view itself.

Wayne Lo
  • 3,689
  • 2
  • 28
  • 28
4

Yes you are right.

When you need to use the view, then you use the frame; the bounds are used to actually implement the view. As an example, you need to use the bounds to draw a view or to handle touch events. Instead, you use the frame when creating a view or positioning a view in its superview etc.

Massimo Cafaro
  • 25,429
  • 15
  • 79
  • 93
4

You are right.

You can use the two interchangably though it's just the frame is easier when using a view and bounds is easier when working inside a view (e.g. in the event handling or drawing code)

Note also that frame is undefined if there is a transform operating on the view.

Rog
  • 17,070
  • 9
  • 50
  • 73
1

http://developer.apple.com/library/ios/#documentation/windowsviews/conceptual/viewpg_iphoneos/WindowsandViews/WindowsandViews.html

For iOS. Origin coordinate is in different location from Mac OS (upper left, not lower left)

Rod Gammon
  • 41
  • 1
  • 7