gcamp
gcamp

Reputation: 14662

Why are the bounds of an UIView a CGRect and not a CGSize?

Is there a reason why the bounds property of UIView (an NSView) are a CGRect when the only information you'll ever want in that property are the size of that CGRect.

Is it just a shortcut for drawing since you'll need a CGRect when drawing? Or just a very specific special case where the origin of the bounds could be something else than {0, 0}?

Upvotes: 5

Views: 1689

Answers (2)

sergio
sergio

Reputation: 69027

The frame specifies where the view is relative to the superview, while bounds specifies where the view is allowed to draw relative to the frame.

By changing the bounds origin and/or width you can get clipping, e.g., or drawing outside of the view.

I.e, bounds origin is normally (0,0) but it must not be always so, like when you do clipping.

Furthermore, bounds is used by affine transformations instead of the frame and it represents the position after transformation which could also have an origin different from (0,0);

Upvotes: 7

Bounds

bounds is inside of UIView means width and height.

(width,height);

Frames

frame is where it should be start relative to its superview and its bounds

(from x,from y ,width,height);

starting point from superview + its bound

Upvotes: 0

Related Questions