This app shows 9 items in a vertical grid with 3 columns. Each item is a blue box with white text. The grid scrolls if needed.
import SwiftUI
struct ContentView: View {
let columns = [
GridItem(.flexible()),
GridItem(.flexible()),
GridItem(.flexible())
]
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 20) {
ForEach(1...9, id: \.self) { number in
Text("Item \(number)")
.frame(height: 50)
.frame(maxWidth: .infinity)
.background(Color.blue.opacity(0.7))
.foregroundColor(.white)
.cornerRadius(8)
}
}
.padding()
}
}
}
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}