0Pricing
SwiftUI Academy · Lesson

Spacer & Layout Priority

Push views apart with Spacer and control sizing.

Meet Spacer

A Spacer is an invisible view that greedily expands to fill empty space inside a stack, pushing its neighbors apart.

Pushing Views Apart

Drop a Spacer between two views in an HStack and they fly to opposite ends, perfect for a label on the left and a value on the right.

HStack {
    Text("Total")
    Spacer()
    Text("$42")
}

All lessons in this course

  1. Adding Padding Around Views
  2. Sizing Views with frame
  3. Backgrounds & Corner Radius
  4. Spacer & Layout Priority
← Back to SwiftUI Academy