Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I have the right understanding of frames and bounds in UIKit?

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?

like image 975
Thanks Avatar asked Apr 20 '09 09:04

Thanks


People also ask

What is a difference between frame and a bounds?

Frame is used by the view's parent view to place it inside the parent view. Bounds is used by the view itself to place it's own content (like a scroll view does while scrolling).

What is a frame in Uikit?

The frame rectangle, which describes the view's location and size in its superview's coordinate system.

What is frame and bound in IOS?

Short description. frame = a view's location and size using the parent view's coordinate system (important for placing the view in the parent) bounds = a view's location and size using its own coordinate system (important for placing the view's content or subviews within itself)

What's a difference between frame and bounds Swift?

TLDR: Bounds refers to the views own coordinate system while Frame refers to the views parent coordinate system.


2 Answers

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

like image 86
calebt Avatar answered Sep 21 '22 05:09

calebt


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.

like image 36
Wayne Lo Avatar answered Sep 21 '22 05:09

Wayne Lo