🌀Gradient + View
╱🚧 under construction -> LinearGradient , Array.first(), Swatch
swift⟩ custom ⟩ extension ⟩ Gradient ⟩ + View

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
}
Last updated
Was this helpful?