ScrollView and Grids
ScrollView
List is great for rows. ScrollView lets you scroll any custom content.
swift
ScrollView {
VStack(spacing: 16) {
ForEach(1...20, id: \.self) { i in
RoundedRectangle(cornerRadius: 12)
.fill(.blue.gradient)
.frame(height: 80)
.overlay(Text("Card \(i)").foregroundStyle(.white))
}
}
.padding()
}
Lazy stacks: A plain
VStack creates all children immediately. LazyVStack creates them only when they come on screen, which is much better for long content.
swift
ScrollView {
LazyVStack(spacing: 12) {
ForEach(0..<1000, id: \.self) { Text("Row \($0)") }
}
}
Horizontal Carousel
swift
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 12) {
ForEach(1...10, id: \.self) { i in
RoundedRectangle(cornerRadius: 16)
.fill(.orange.gradient)
.frame(width: 140, height: 180)
.overlay(Text("\(i)").font(.largeTitle).foregroundStyle(.white))
}
}
.scrollTargetLayout()
.padding(.horizontal)
}
.scrollTargetBehavior(.viewAligned) // snaps to each card
LazyVGrid
swift
struct PhotoGrid: View {
// three equal flexible columns
let columns = [GridItem(.flexible()), GridItem(.flexible()), GridItem(.flexible())]
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 8) {
ForEach(1...30, id: \.self) { i in
Rectangle()
.fill(Color(hue: Double(i) / 30, saturation: 0.6, brightness: 0.9))
.aspectRatio(1, contentMode: .fit)
.overlay(Text("\(i)"))
}
}
.padding(8)
}
}
}
| GridItem | Behavior |
|---|---|
.fixed(100) | Exact width |
.flexible() | Shares the free space |
.adaptive(minimum: 100) | As many columns as fit, each at least 100 |
swift
let adaptive = [GridItem(.adaptive(minimum: 100), spacing: 8)] // more columns on iPad automatically
Pinned Headers
swift
ScrollView {
LazyVStack(pinnedViews: [.sectionHeaders]) {
ForEach(["A", "B", "C"], id: \.self) { letter in
Section {
ForEach(1...5, id: \.self) { Text("\(letter)\($0)").padding() }
} header: {
Text(letter).frame(maxWidth: .infinity, alignment: .leading)
.padding().background(.regularMaterial)
}
}
}
}
Scroll to a Position
swift
ScrollViewReader { proxy in
ScrollView {
Button("Go to bottom") { withAnimation { proxy.scrollTo(99, anchor: .bottom) } }
LazyVStack {
ForEach(0..<100, id: \.self) { Text("Row \($0)").id($0) }
}
}
}
Conclusion
Use ScrollView with lazy stacks for custom scrolling, and LazyVGrid with adaptive columns for galleries that fit every screen size.
Quick Summary: ScrollView scrolls custom content, Lazy stacks load on demand and LazyVGrid with GridItem builds responsive grids.

