How to add color gradient as Text color in SwiftUI
The “Hello, World!“ Text above is written completely in SwiftUI. In this tutorial we are doing this with Text, however you can do this with any View you wish to use.
The code above produces the colorful text you saw earlier. The code above does the following.
Define your gradient: You can use any of the gradient types in SwiftUI.
Mask your gradient with the text view: Masking allows for you to replace any color in the view with the gradient. For example default text color is black, gradient shadows over the black text color to display the colorful gradient as the color for the text.