๐ธcolor.gradient
standard gradient for the color.
SwiftUI โฉ shapes โฉ ShapeStyle โฉ Color โฉ .gradient

import SwiftUI
struct StandardGradientView: 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
ColorSwatch(color: color, size: 80)
}
}.padding()
}
}
// previews
struct StandardGradientView_Previews: PreviewProvider {
static var previews: some View {
StandardGradientView()
}
}Last updated
Was this helpful?