import SwiftUI
struct PhotoGalleryView: View {
let columns = Array(repeating: GridItem(.fixed(60), spacing: 10), count: 5)
var body: some View {
ScrollView {
LazyVGrid(columns: columns, spacing: 10) {
ForEach(1...20, id: \.self) { number in
ZStack {
RoundedRectangle(cornerRadius: 8)
.fill(Color(hue: Double(number) / 20.0, saturation: 0.7, brightness: 0.8))
.frame(width: 60, height: 60)
Text("\(number)")
.font(.headline)
.foregroundColor(.white)
}
}
}
.padding()
}
}
}
struct PhotoGalleryView_Previews: PreviewProvider {
static var previews: some View {
PhotoGalleryView()
}
}We define 5 columns using GridItem(.fixed(60)) to make each column 60 points wide. The LazyVGrid arranges items vertically in these columns. We loop from 1 to 20 to create 20 squares. Each square is a rounded rectangle with a color that changes hue based on the number, making the grid colorful. The number is shown centered in white text. The grid scrolls vertically inside a ScrollView. Padding and spacing keep the layout neat.