来自 Paul Hudson hackingwithswift.com 的代码
extension View {
func multicolorGlow() -> some View {
ZStack {
ForEach(0..<2) { i in
Rectangle()
.fill(AngularGradient(gradient: Gradient(colors: [.red, .yellow, .green, .blue, .purple, .red]), center: .center))
.frame(width: 400, height: 300)
.mask(self.blur(radius: 20))
.overlay(self.blur(radius: 5 - CGFloat(i * 5)))
}
}
}
}
这里是如何运行扩展程序:
struct ContentView: View {
var body: some View {
Text("Hello World")
.font(.system(size: 96, weight: .black, design: .rounded))
.foregroundColor(.white)
.multilineTextAlignment(.center)
.frame(width: 400, height: 300)
.multicolorGlow()
}
}