Stage 2 · Lesson 4 of 10
VStack, HStack, ZStack and spacing
arranges views from top to bottom, HStack side by side and ZStack layers them, like a badge on an avatar. Each takes alignment and spacing settings. Spacer() pushes views apart by taking all the free space.
layout works by offering: a parent suggests a size, the child picks its own, and the parent places it. .frame(maxWidth: .infinity) makes a view as wide as it can be. .lineLimit and .layoutPriority decide which text shrinks first when space runs out. Prefer these over fixed frames so screens adapt.
Common trapfixed widths from a design mock-up, which clip text on the smallest iPhone.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CourseFreeSwiftUI Tutorials (Apple)
Apple · Beginner
Apple's own path from views and stacks to lists and navigation
- CourseFree100 Days of SwiftUI
Paul Hudson (Hacking with Swift) · Beginner
Days 16 to 35 build six small apps on views, modifiers, lists and animation