๐Ÿ–ผ๏ธStandardGradientGrid

SwiftUI โŸฉ layout โŸฉ grids โŸฉ LazyVGrid โŸฉ

LazyVGrid (8 fixed columns)
import SwiftUI

struct StandardGradientGrid: View {

    let spacing: CGFloat = 8
    let width: CGFloat = 80    // column width
    
    // 8 columns
    var columns: [GridItem] {
        // โญ๏ธ last GridItem's spacing is ignored.
        Array(
            repeating: GridItem(
                .fixed(width),        // โญ๏ธ fixed width
                spacing: spacing+6    // spacing to next column
            ), 
            count: 8
        )
    }
    
    var body: some View {
        // โญ๏ธ lazy v grid
        LazyVGrid(columns: columns, spacing: spacing) { // spacing between rows
            ForEach(Color.standardColors, id: \.self) { color in
                Swatch(name: color.name, size: 80) { color.gradient }
            }
        }.padding() 
    }
}

// previews
struct StandardGradientGrid_Previews: PreviewProvider {
    static var previews: some View {
        StandardGradientGrid()
    }
}

Last updated

Was this helpful?