SwiftUI Styling Color Schemes
Use light/dark modes and the system color palette to keep your UI readable and consistent.
Read the current color scheme
Access the environment’s color scheme to adapt your UI for light or dark mode.
Example
Demo.swift
ContentView.swift
App.swift
import SwiftUI
struct ColorSchemesDemo: View {
@Environment(\.colorScheme) var scheme
var body: some View {
Text(scheme == .dark ? "Scheme: Dark" : "Scheme: Light")
.padding()
}
}
Leave a Reply