布局Layout
LazyVGridLazyVGrid
构建自适应网格布局,适合相册、卡片列表和仪表盘。Builds adaptive grids for galleries, card lists, and dashboards.
中级Intermediate • 5 分钟5 min
更新于Updated Apr 22, 2026
自适应网格Adaptive Grid
LazyVGrid 能在有限空间里高效渲染大量卡片,并支持自适应列宽。LazyVGrid efficiently renders many cards and supports adaptive columns.
自适应卡片Adaptive Cards
swift
1let columns = [GridItem(.adaptive(minimum: 160), spacing: 16)]23LazyVGrid(columns: columns, spacing: 16) {4 ForEach(cards) { card in5 CardView(card: card)6 }7}
CardView
CardView
CardView
CardView
适用场景Use Cases
当内容数量多、单元格尺寸相近,并且需要随屏幕宽度自动换列时,优先考虑 LazyVGrid。Use LazyVGrid when there are many similarly sized cells that should adapt to screen width.