Layout SwiftUI reference
Focused SwiftUI layout pages with original examples, usage guidance, and implementation notes.
Layer views deliberately with background, overlay, and zIndex while keeping the base layout stable.
Reach for alignment guides and coordinate spaces when default stack alignment is not expressive enough.
Pass child measurements up the view tree with PreferenceKey when a parent needs information children know first.
HStack lays out children left to right with a shared vertical alignment. layoutPriority decides which child shrinks first when space runs out.
ZStack overlays children back to front with a shared alignment. Combine it with ignoresSafeArea for full-bleed backgrounds without pushing content under the notch.
Grid aligns cells into true rows and columns, sizing each column to its widest cell. gridCellColumns spans columns and gridCellUnsizedAxes stops decoration from inflating the grid.
Spacer is a flexible blank view that absorbs leftover space along a stack's axis. Use minLength to keep a guaranteed gap and multiple Spacers for proportional layouts.