What is the difference between `frame` and `bounds` of a `UIView`?

iOS interview question for Intermediate practice.

Answer

frame is in the superview's coordinate system, bounds is in the view's own coordinate system.

Explanation

The frame (CGRect) describes the view's position (origin) and size relative to its superview's coordinate system. The bounds (CGRect) describes the view's internal drawing rectangle relative to its own coordinate system. The bounds.origin is almost always (0,0), and bounds.size represents the actual drawing space available. Option B reverses this. While transforms affect the frame (C), the core difference is the coordinate system. They are only identical in specific circumstances (D).

Related Questions