SwiftUI Layout — Stacks, Spacer, List

Stacks

StackAxis
ZStackDepth — front and back
VStackVertical — up and down
HStackHorizontal — left and right

Original page had a screenshot here.

Original page had a screenshot here.

Spacer()

Adds maximum space between Views. Multiple Spacers spread out equally.

Original page had a screenshot here.

List

List(array-name) { variable in
    // Insert functionality that will affect each item in the array.
    // The variable is the name that you set for each item in the array.
    // It's like a for loop
}
.listStyle

Useful list modifiers

  • .listStyle(.plain) — list style
  • .listRowSeparator(.hidden) — hides the separator lines
  • .listRowBackground(Color(.brown).opacity(0.1)) — change row background colour

See next