ContentView.swift
struct ContentView: View {
var body: some View {
ScrollView {
LazyVStack{
ForEach(0..<10) {
num in Page(str: String(num))
.frame(width:200, height: 150)
.cornerRadius(8)
}
}
}
.frame(width: 250, height: 500)
.background(Color.gray.opacity(0.2))
}
}
struct Page: View {
let colors:[Color] = [.green, .blue, .pink, .orange, .purple]
let str:String
var body: some View {
ZStack {
colors.randomElement()
Text(str)
.font(.largeTitle)
.foregroundColor(.white)
}
}
}

横スクロール
struct ContentView: View {
let w:CGFloat = UIScreen.main.bounds.width-20
var body: some View {
VStack(alignment: .leading){
Text("横スクロール").padding([.leading])
ScrollView(.horizontal){
LazyHStack(alignment: .center, spacing: 10){
ForEach(0..<10) {
num in Page(str: String(num))
.frame(width: w, height: 150)
.cornerRadius(8)
}
}
}
.frame(height: 200)
.background(Color.gray.opacity(0.2))
}
}
}

LazyVStackとLazyHStackで見えてるところをスクロールさせるのね
なるほど、少しずつキャズムに足を踏み入れることが出来る様になってきた…