试图用渐变模糊我的圆圈,但不明白为什么它不起作用。有人有想法吗?或者这还不支持吗?
struct GradientExperiment: View {
var body: some View {
VStack {
//blur works
Circle()
.fill(Color(.blue))
.frame(width: 50, height: 50)
.blur(radius: 10)
//blur does not work
Circle()
.fill(LinearGradient(gradient: Gradient(colors: [.blue,.red]), startPoint: .bottom, endPoint: .top))
.frame(width: 50, height: 50)
.blur(radius: 10)
}
}
}
最佳答案
向 LinearGradient
添加蒙版并使用 Circle
作为蒙版:
LinearGradient(gradient: Gradient(colors: [.blue, .red]), startPoint: .bottom, endPoint: .top)
.mask(
Circle()
.frame(width: 50, height: 50)
.blur(radius: 10)
)
关于gradient - 我们如何在 SwiftUI 中使用渐变模糊形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60195662/