SwiftUI Styling Color Schemes

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()
} }

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *