๐ŸŒ€Gradient + View

โ•ฑ๐Ÿšง under construction -> LinearGradient , Array.first(), Swatch

swiftโŸฉ custom โŸฉ extension โŸฉ Gradient โŸฉ + View

Let Gradient and AnyGradient comform to 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?