我想要swiftUI中的所有侧面渐变阴影按钮

问题描述 投票:0回答:1

我想在swiftUI按钮中实现这种渐变阴影。任何帮助或建议将不胜感激。我已经实现了渐变边框。预先感谢!

ios swift swiftui gradient shadow
1个回答
0
投票

来自 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()
}

}

© www.soinside.com 2019 - 2024. All rights reserved.