SwiftUI Color
Published Mar 2, 2023
Contribute to Docs
A Color view is a way to incorporate colors into the user interface. It can be used to modify the backgrounds.
Syntax
var body: some View {
Color.color-example
//Content that is being modified
.foregroundColor(.color-example) //Modifier
}
Color.color-examplechanges the background color..foregroundColor(.color-example)changes the color of the content (ex: “text”) itself.
Example
The following example changes the colors to white on black:
var body: some View {VStack {Color.black.overlay(Text("Codecademy__").foregroundColor(.white))}.padding()}
Color.blackmakes the background color black.foregroundColor(.white)sets the text color to white.
The code-block above will display an interface filled with the color black and the text “Codecademy” in white.

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
- Learn how to build iOS applications with Swift and SwiftUI and publish them to Apples' App Store.
- Includes 7 Courses
- With Certificate
- Beginner Friendly.13 hours