Difference between frame and bounds in iOS iOS 15.11.2019

Both the frame and bounds of a view refer to a rectangle, defined by a CGRect object that contains the size (width and height) and origin (x and y) of the view. The origin of a CGRect object usually refers to the upper-left corner.

The difference between frame and bounds is that frame is seen from the perspective of the view’s superview coordinate system, and bounds is seen from the perspective of the view’s own coordinate system.

As you can see in the view in the example, the size of the bounds is often the same as the size as the frame of a view. The origin, on the other hand, often differs, depending on the perspective.

ios_frame_bounds1.png

If you apply any transformations to the rectangle, however, such as scaling or rotation, the size of a view can look different from the perspective of a view’s own coordinate system or its superview’s. Scale a view 50% such as in the example, and the size of its bounds won’t change, but from the perspective of its superview, the size of its frame has shrunk by half.

ios_frame_bounds2.png

Useful links