iOS UIView - kgleong/software-engineering GitHub Wiki

UIView

Positiong properties

CGRect

  • A struct containing the following sub structs:
    • Origin - A CGPoint representing the top left corner of a frame or bounds.
    • Size - A CGSize struct representing the width and length.

Frame Describes the minimal bounding box for the view with respect to the parent view's coordinate system. This also takes into account any transformations (e.g., rotation, scaling) that have been applied.

This is a computed property.

Calculated using the bounds, position, and transform.

Changing the frame may also update these dependent properties as well.

According to Apple's documentation on the frame property, be wary of the view.frame property when transforms are applied.

If transformations may be applied to a view, then it's better to reference the center and bounds when repositioning the view.

This is because the frame property is undefined after a non-identity transformation is applied.

Bounds

Center A CGPoint that represents the center of view with respect to the parent's coordinate system.

References

Initializers

References

Lifecyle

Callback Trigger
init(frame:)
init(coder:)
willMoveToSuperview
invalidateIntrinsicContentSize
didMoveToSuperview The view has been added to a view hierarchy. self.superview is now populated.
awakeFromNib
willMoveToWindow
needsUpdateConstraints
didMoveToWindow
layoutSubviews
drawRect

References

Custom Interface Builder UIView

References

Navigation Controller interactions

Extending the view under the navigation bar

var viewController = UIViewController()

// The top of the view will be under the status bar the navigation bar,
// if present.
viewController.edgesForExtendedLayout = UIRectEdge.None

// The root view fills the entire screen, including under the status bar and
// under a navigation bar if present.
viewController.edgesForExtendedLayout = UIRectEdge.All

All UIRectEdge values

References