.foregroundColor()
Published Feb 27, 2023Updated Mar 3, 2023
Contribute to Docs
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:
Contribute to Docs
- 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.
Learn SwiftUI on Codecademy
- Skill path
Build iOS Apps with SwiftUI
Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.Includes 7 CoursesWith CertificateBeginner Friendly13 hours - Free course
Learn Swift
A powerful programming language developed by Apple for iOS, macOS, and more.Beginner Friendly12 hours