UICollectionViewのようにViewを並べる
UICollectionViewのようにViewを並べる方法です。
ContentView.swift
import SwiftUI
struct ContentView: View {
let columns = [GridItem(.fixed(80)), GridItem(.fixed(80)), GridItem(.fixed(80)), GridItem(.fixed(80))]
var body: some View {
ScrollView {
LazyVGrid(columns: columns) {
ForEach(0..<100, id: \.self) { number in
Text("\(number)")
.foregroundStyle(Color.white)
.font(.title)
.frame(width: 80, height: 80)
.background(Color.gray)
}
}
}
}
}
#Preview {
ContentView()
}
