Home > AI > IOS > SwiftUI >

Image Grid 3X3

struct TestGridView: View {
    
    let data = Array(1...9).map {"free-course-\($0)"}
    
    let layout = [
        GridItem(.flexible()),
        GridItem(.flexible()),
        GridItem(.flexible())
    ]
    var body: some View {
        ScrollView {
            LazyVGrid(columns: layout, spacing:10) {
                ForEach(data, id: \.self) { item  in
                    Image("\(item)")
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                }
                
            }.padding(.horizontal)
        }
    }
}
Relevant tags:

Leave a Reply