ColorScheme
The possible color schemes, corresponding to the light and dark appearances.
Declaration
enum ColorSchemeOverview
You receive a color scheme value when you read the colorScheme environment value. The value tells you if a light or dark appearance currently applies to the view. SwiftUI updates the value whenever the appearance changes, and redraws views that depend on the value. For example, the following Text view automatically updates when the user enables Dark Mode:
@Environment(\.colorScheme) private var colorScheme
var body: some View {
Text(colorScheme == .dark ? "Dark" : "Light")
}Set a preferred appearance for a particular view hierarchy to override the user’s Dark Mode setting using the preferredColorScheme(_:) view modifier.