iOS Simulator
Dark Mode
iOS Development
App Testing
Developer Tools

How to turn on dark mode in the iOS Simulator

Codemia Knowledge Hub ·

To turn on dark mode in the iOS Simulator, open Settings > Display & Brightness on the simulated device and select Dark, or use the Environment Overrides panel in Xcode's debug bar. From the terminal, xcrun simctl ui <device> appearance dark switches instantly. All three do the same thing; the terminal command is fastest if you switch often.

If your colors, images or text assume a light background, dark mode exposes that immediately, and the Simulator lets you check both appearances without a physical device.

Settings app in the Simulator

This mirrors what a user does on a real iPhone or iPad.

  1. Open the Simulator (launch it from Xcode or run open -a Simulator in Terminal).
  2. Go to Settings > Display & Brightness.
  3. Under Appearance, tap Dark.

The change applies immediately to every app on the device, including the home screen and system UI. Tap Light to switch back.

Under Display & Brightness > Automatic you can also set a schedule, which is useful for testing dynamic appearance changes without toggling by hand.

Xcode Environment Overrides

The fastest option when you are already debugging in Xcode.

  1. Run your app on the Simulator from Xcode.
  2. In the debug area's bottom toolbar, click the Environment Overrides button (a small slider icon, also under Debug > View Debugging > Environment Overrides).
  3. Toggle Interface Style to Dark.

The override applies while your app runs and does not change the Simulator's system setting, so other apps keep their previous mode. Because it is a single click, it suits rapid back-and-forth while inspecting layouts.

xcrun simctl ui from the terminal

simctl controls the Simulator from Terminal, which makes it the best choice for scripts, CI pipelines and keyboard users.

bash
1# Switch to dark mode
2xcrun simctl ui booted appearance dark
3
4# Switch to light mode
5xcrun simctl ui booted appearance light
6
7# Check current appearance
8xcrun simctl ui booted appearance

booted targets the running Simulator. If several are running, use a specific device UDID:

bash
1# List available simulators and their UDIDs
2xcrun simctl list devices
3
4# Target a specific simulator
5xcrun simctl ui 4A2B7C8D-1234-5678-ABCD-EF0123456789 appearance dark

Screenshot tests in both modes

Set the appearance before launching the test suite:

bash
1#!/bin/bash
2# Capture screenshots in both modes
3
4xcrun simctl ui booted appearance light
5xcodebuild test -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 15'
6
7xcrun simctl ui booted appearance dark
8xcodebuild test -scheme MyApp -destination 'platform=iOS Simulator,name=iPhone 15'

Comparing the three methods

MethodSpeedRequires Xcode Debug SessionScriptablePersists After App Restart
Settings appSlow (navigate through UI)NoNoYes
Environment OverridesFast (one click)YesNoNo (override only)
xcrun simctl uiFastest (command line)NoYesYes

Because Environment Overrides do not persist, testing only with them misses bugs that appear when the app launches in dark mode (for example, launch screen colors). Test the initial launch through Settings or simctl too.

Making your app adapt to dark mode

Semantic system colors

UIKit semantic colors adapt automatically. Hard-coded colors like UIColor.white or UIColor.black do not, and look wrong in the opposite mode.

swift
label.textColor = .label           // Black in light, white in dark
view.backgroundColor = .systemBackground  // White in light, black in dark
detailLabel.textColor = .secondaryLabel    // Gray, adapts to both modes

Custom dynamic colors

When system colors are not enough, define colors that resolve from the current trait collection:

swift
1let cardBackground = UIColor { traitCollection in
2    switch traitCollection.userInterfaceStyle {
3    case .dark:
4        return UIColor(red: 0.15, green: 0.15, blue: 0.17, alpha: 1.0)
5    default:
6        return UIColor(red: 0.97, green: 0.97, blue: 0.98, alpha: 1.0)
7    }
8}
9
10cardView.backgroundColor = cardBackground

Asset catalog variants

  1. Select an image or color in Assets.xcassets.
  2. In the Attributes Inspector, set Appearances to Any, Dark (or Any, Light, Dark).
  3. Drag the right assets into each slot.

UIKit picks the correct variant at runtime with no code changes. Without dark variants, a bright logo on a dark background, or a dark icon on a dark background, becomes jarring or invisible.

SwiftUI

SwiftUI reacts to appearance through @Environment:

swift
1struct ContentView: View {
2    @Environment(\.colorScheme) var colorScheme
3
4    var body: some View {
5        Text("Hello, World!")
6            .foregroundColor(colorScheme == .dark ? .white : .black)
7            .background(colorScheme == .dark ? Color.black : Color.white)
8    }
9}

In most cases the built-in semantic colors (Color.primary, Color.secondary, Color(.systemBackground)) are enough and you do not need to read colorScheme.

Reacting to appearance changes at runtime

Users can switch modes while your app is in the foreground. If you cache colors at startup without listening for trait changes, the UI shows stale colors. In UIKit, override traitCollectionDidChange to update non-UIKit components:

swift
1override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
2    super.traitCollectionDidChange(previousTraitCollection)
3
4    if traitCollection.hasDifferentColorAppearance(comparedTo: previousTraitCollection) {
5        // Update non-UIKit components, charts, WebViews, etc.
6        updateChartColors()
7    }
8}

This callback is for UIKit-based views. In SwiftUI, use @Environment(\.colorScheme) instead.

Debugging dark mode issues

  • Contrast: the Accessibility Inspector (Xcode > Open Developer Tool > Accessibility Inspector) overlays contrast information on the Simulator in real time so you can check ratios against WCAG.
  • Hard-coded colors: the View Debugger (Debug > View Debugging > Capture View Hierarchy) shows which colors each view uses. Look for white backgrounds and black text that do not adapt.

Forcing an appearance per view controller

swift
1// Force dark mode regardless of system setting
2overrideUserInterfaceStyle = .dark
3
4// Force light mode
5overrideUserInterfaceStyle = .light
6
7// Follow system setting (default)
8overrideUserInterfaceStyle = .unspecified

This helps compare the two modes side by side in split-view debugging. It is a debugging tool: shipping overrideUserInterfaceStyle = .dark in production disables the user's system preference for your whole app.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
Data Structures & Algorithms practice on Codemia

Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.

Practice algorithms