top of page
Writer's pictureHui Wang

99. SwiftUI: Creating flexible grid layout using LazyVGrid

Code:

import SwiftUI

struct ContentView: View {
    private var items: [GridItem] = [
        GridItem(.flexible(), spacing: 10),
        GridItem(.fixed(140), spacing: 10),
        GridItem(.flexible(), spacing: 10)
    ]
    
    var body: some View {
        ScrollView {
            LazyVGrid(columns: items) {
                ForEach(1...10, id: \.self) { index in
                    Image("myImage\(index)")
                        .resizable()
                        .frame(height: 100)
                }
            }
        }
        .padding()
    }
}



 

Follow me on:

Comments


bottom of page