Layout

Tell a view how to arrange itself within a view hierarchy by adjusting its size, position, alignment, padding, and so on.

Topics

Sizing a View

func frame(width: CGFloat?, height: CGFloat?, alignment: Alignment) -> View

Positions the view within an invisible frame with the specified size.

func fixedSize() -> View

Fixes the view at its ideal size.

func fixedSize(horizontal: Bool, vertical: Bool) -> View

Fixes the view at its ideal size in the specified dimensions.

func layoutPriority(Double) -> View

Sets the priority by which a parent layout should apportion space to the child.

Positioning a View

func position(CGPoint) -> View

Fixes the center of the view at the specified point in its parent’s coordinate space.

func position(x: CGFloat, y: CGFloat) -> View

Fixes the center of the view at the specified coordinates in its parent’s coordinate space.

func offset(CGSize) -> View

Offsets the view by the horizontal and vertical distances in the given size.

func offset(x: CGFloat, y: CGFloat) -> View

Offsets the view by the specified horizontal and vertical distances.

func edgesIgnoringSafeArea(Edge.Set) -> View

Extends the view out of the safe area on the specified edges.

func coordinateSpace<T>(name: T) -> View

Assigns a name to this view’s coordinate space to which descendants of this view can refer.

Aligning Views

struct ViewDimensions

A view’s size and its alignment guides in its own coordinate space.

protocol AlignmentID

Types used to identify alignment guides.

Adjusting the Padding of a View

func padding(CGFloat) -> View

Pads the view along all edge insets by the specified amount.

func padding(EdgeInsets) -> View

Pads the view using the specified edge insets.

func padding(Edge.Set, CGFloat?) -> View

Pads the view using the specified edge insets.

struct EdgeInsets

The inset distances for the sides of a rectangle.

Layering Views

func overlay<Overlay>(Overlay, alignment: Alignment) -> View

Layers a secondary view in front of the view.

func zIndex(Double) -> View

Controls the display order of overlapping views.

See Also

Configuring Views

Accessibility

Make your views accessible to a broad range of users, including people with disabilities.

Rendering

Affect the way the system draws a view, for example by scaling or masking a view, or by applying graphical effects.

Styling

Indicate how to style the text, controls, and other content contained in a view.