.foregroundColor()
The .foregroundColor()
modifier sets the foreground color displayed in a view.
Syntax
Text("We are setting the foreground color to green!")
.foregroundColor(color)
The .foregroundColor()
applies the color
to the Text
which conforms to the View
protocol.
Example
struct ContentView: View {var body: some View {Text("We are setting the foreground color to green!").foregroundColor(.green)}}
In the above example, the .foregroundColor()
modifier with the .green
parameter is called on the Text
view. This applies the color green to all characters.
This will display the following: