top of page

99. SwiftUI: Creating flexible grid layout using LazyVGrid

Writer's picture: Hui WangHui Wang

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:

留言


Never Miss a Post. Subscribe Now!

I am an iOS developer, and I will share some knowledge related to iOS development from time to time.

Thanks for submitting!

© 2022 by (Foks) Hui Wang

bottom of page