import SwiftUI
// Gradient + View
// now `Gradient` is a view.
extension Gradient: View {
public var body: some View {
Rectangle().fill(self)
}
}
// AnyGradient + View
// now `AnyGradient` is a view.
extension AnyGradient: View {
public var body: some View {
Rectangle().fill(self)
}
}
๐ Previews
// previews
struct GradientViewExample_Previews: PreviewProvider {
// first 11 standard colors
static let colors = Array(Color.standardColors.prefix(11))
static var previews: some View {
HStack {
ForEach(colors, id: \.self){color in
Swatch(name: color.name, size: 60){ // ๐ผ๏ธ custom view
color.gradient // ๐ AnyGradient + View
}
}
}
}// previews
}