Colors
Part of the Introduction to SwiftUI section of Coddy's Swift journey. Lesson 6 of 50.
.foregroundStyle colors a view's content, such as the letters of a Text:
Text("Warning")
.foregroundStyle(.red)SwiftUI has named colors: .red, .orange, .yellow, .green, .blue, .purple, .gray and more. .secondary is the softer gray used for less important text.
Older code uses .foregroundColor(.red), which does the same for a single color. You can also mix a color from red, green and blue parts between 0 and 1:
Text("Custom")
.foregroundStyle(Color(red: 0.2, green: 0.6, blue: 0.9))Challenge
BeginnerShow that the cafe is open: make the text green and give it the .headline font.
Try it yourself
import SwiftUI
@main
struct CoddyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Introduction to SwiftUI
Practice on your own: Swift playground