0PricingLogin
SwiftUI Academy · Lesson

Adaptive Grids with LazyVGrid

Lay out cards in flexible grid columns.

Why a Grid?

Stacks give you rows or columns, but a LazyVGrid arranges items into neat rows and columns, like a photo album. 🖼️

Define the Columns

A LazyVGrid needs a columns array of GridItem values that describe how many tracks to lay out.

let columns = [GridItem(), GridItem()]
LazyVGrid(columns: columns) {
    ForEach(items) { Cell($0) }
}

All lessons in this course

  1. Horizontal & Vertical ScrollView
  2. LazyVStack & LazyHStack
  3. Adaptive Grids with LazyVGrid
  4. ScrollView Reader & Anchors
← Back to SwiftUI Academy