Homepage /Articles/Neon style in SwiftUI
A neon styled text saying Neon style with a bolt.Nov 22, 2021

Neon style in SwiftUI

struct NeonStyle: ViewModifier {
    let color: Color

    func body(content: Content) -> some View {
        content
            .foregroundColor(color).brightness(0.3)
            .shadow(color: color, radius: 10, x: 0, y: 0)
    }
}

extension View {
    func neon(color: Color) -> some View {
        modifier(NeonStyle(color: color))
    }
}

/* Usage */
Label("Neon effect", systemImage: "bolt.fill")
    .font(.system(.largeTitle, design: .rounded))
    .neon(color: .yellow)
    .padding()
    .padding()
    .overlay(
        RoundedRectangle(cornerRadius: 8)
            .stroke(lineWidth: 4)
            .neon(color: .yellow)
    )