.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:
All contributors
- awgraves5 total contributions
- Beamthecode2 total contributions
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.