iosswiftuser-interfaceswiftui

Gradient as foreground color of Text in SwiftUI


Is there any way of using a gradient as foregroundColor of Text in SwiftUI?

Thanks for the answers in advance!


Solution

  • New in SwiftUI: modifier .foregroundStyle() (iOS15+)

    Text with a gradient

    Text(“Gradient”)
        .foregroundStyle(
            .linearGradient(
                colors: [.red, .blue],
                startPoint: .top,
                endPoint: .bottom
            )
        )