iosswiftswiftui

How to make a gradient shadow in SwiftUI


I have a RoundedRectangle with a gradient border and I want to add a gradient shadow that matches the colors of the gradient border to make it glow.

 RoundedRectangle(cornerRadius: 5)
     .strokeBorder(getBorderGradient(appGroup.isProductive), lineWidth: 2)
     .shadow(color: .neon.opacity(0.3), radius: 4, x: 0, y: 0)

Solution

  • How about using blur?

    ZStack {
        RoundedRectangle(cornerRadius: 5)
            .strokeBorder(Gradient(colors: [.blue, .red]), lineWidth: 2)
            .padding(20)
            .blur(radius: 4) // like shadow
        RoundedRectangle(cornerRadius: 5)
            .strokeBorder(Gradient(colors: [.blue, .red]), lineWidth: 2)
            .padding(20)
    }