SwiftUI.cc
SwiftUI collection

Layout SwiftUI reference

Focused SwiftUI layout pages with original examples, usage guidance, and implementation notes.

Showing 1-9 of 14 reference pages
Page 1 of 2Next

Control layout by combining flexible frames, padding, fixedSize, and layoutPriority rather than guessing with offsets.

5 min readOpen

Layer views deliberately with background, overlay, and zIndex while keeping the base layout stable.

4 min readOpen

Reach for alignment guides and coordinate spaces when default stack alignment is not expressive enough.

5 min readOpen

Pass child measurements up the view tree with PreferenceKey when a parent needs information children know first.

6 min readOpen

VStack arranges children top to bottom and sizes itself to fit them. Control the gap with the spacing parameter and the horizontal placement with alignment.

4 min readOpen

HStack lays out children left to right with a shared vertical alignment. layoutPriority decides which child shrinks first when space runs out.

4 min readOpen

ZStack overlays children back to front with a shared alignment. Combine it with ignoresSafeArea for full-bleed backgrounds without pushing content under the notch.

4 min readOpen

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.

5 min readOpen

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.

3 min readOpen