How to use dark mode in iOS simulator?
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
To enable dark mode in the iOS Simulator, go to Settings > Display & Brightness in the simulated device and select Dark, or toggle it from Xcode's debug bar using the Environment Overrides panel. You can also switch appearance instantly from the terminal with xcrun simctl ui <device> appearance dark. All three approaches do the same thing, but the terminal command is the fastest for developers who switch frequently during testing.
Dark mode testing is not optional for any app that ships to the App Store. If your colors, images, or text rely on a light background, dark mode will expose those assumptions immediately. The Simulator provides every tool you need to validate both appearances without deploying to a physical device.
Method 1: Settings App in the Simulator
This mirrors exactly what a user does on a real iPhone or iPad.
- Open the Simulator (launch it from Xcode or run
open -a Simulatorin Terminal). - Navigate to Settings > Display & Brightness.
- Under Appearance, tap Dark.
The change takes effect immediately. Every app on the simulated device switches to dark mode, including the home screen and system UI.
To switch back, tap Light in the same settings panel.
Automatic Appearance Schedule
The Simulator also supports the automatic light/dark schedule. Under Display & Brightness > Automatic, you can set the appearance to change based on a schedule. This is useful for testing how your app handles dynamic appearance changes without manually toggling.
Method 2: Xcode Environment Overrides
This is the fastest method when you are already debugging an app in Xcode.
- Run your app on the Simulator from Xcode.
- In Xcode's debug area (bottom toolbar), click the Environment Overrides button (it looks like a small slider icon, or find it under Debug > View Debugging > Environment Overrides).
- Toggle Interface Style to Dark.
The override takes effect immediately while your app is running. It does not change the Simulator's system-level setting, so other apps still appear in their previous mode.
This is particularly useful for toggling back and forth rapidly while inspecting layout changes, because the toggle is a single click.
Method 3: Terminal Command with simctl
The simctl command-line tool controls the Simulator from Terminal. This is the best approach for scripting, CI pipelines, or developers who prefer the keyboard.
The booted keyword targets whatever Simulator is currently running. If multiple Simulators are running, replace booted with a specific device UDID.
Integrating with Screenshot Tests
For automated UI testing, you can set the appearance before launching your test suite.
Method Comparison
| Method | Speed | Requires Xcode Debug Session | Scriptable | Persists After App Restart |
| Settings app | Slow (navigate through UI) | No | No | Yes |
| Environment Overrides | Fast (one click) | Yes | No | No (override only) |
xcrun simctl ui | Fastest (command line) | No | Yes | Yes |
Implementing Dark Mode Support in Your App
Testing dark mode is only useful if your app actually adapts to the appearance. Here are the key implementation patterns.
System Colors
UIKit provides semantic colors that automatically adapt. Using these is the simplest path to dark mode support.
Custom Dynamic Colors
When system colors are not sufficient, define colors that resolve differently based on the current trait collection.
Asset Catalog Variants
For images, icons, and color definitions, Xcode's asset catalog supports appearance variants directly.
- Select an image or color in Assets.xcassets.
- In the Attributes Inspector, set Appearances to Any, Dark (or Any, Light, Dark).
- Drag the appropriate assets into each slot.
At runtime, UIKit automatically picks the correct variant based on the current appearance. No code changes required.
SwiftUI
SwiftUI uses the @Environment property wrapper to react to appearance changes.
For most cases, using SwiftUI's built-in semantic colors (Color.primary, Color.secondary, Color(.systemBackground)) is sufficient and does not require reading colorScheme manually.
Detecting Appearance Changes at Runtime
If your app needs to react programmatically when the user toggles dark mode (for example, to update a non-UIKit component), override traitCollectionDidChange.
Debugging Dark Mode Issues
Color Contrast Verification
Use the Accessibility Inspector (open from Xcode > Open Developer Tool > Accessibility Inspector) to verify contrast ratios meet WCAG standards. The tool overlays contrast information on the Simulator in real time.
View Hierarchy Debugger
Xcode's View Debugger (Debug > View Debugging > Capture View Hierarchy) lets you inspect which colors each view is using. Look for hard-coded colors (white backgrounds, black text) that do not adapt.
Overriding Appearance Per View Controller
For testing, you can force a specific appearance on a single view controller.
This is useful for comparing the two modes side by side in split-view debugging scenarios.
Common Pitfalls
- Hard-coding colors like
UIColor.whiteorUIColor.blackinstead of using semantic colors. These do not adapt and look wrong in the opposite mode. Use.systemBackground,.label, and the other semantic alternatives. - Forgetting to provide dark variants for images in the asset catalog. A bright logo on a dark background, or a dark icon on a dark background, becomes invisible or jarring.
- Testing only with Environment Overrides and not with the Settings app. Environment Overrides do not persist, so you miss bugs that appear on app launch in dark mode (e.g., launch screen colors).
- Not testing the transition between modes. Users can switch modes while your app is in the foreground. If you cache colors at startup without listening for trait changes, the UI will show stale colors after a switch.
- Assuming
traitCollectionDidChangefires on every appearance change in SwiftUI. In SwiftUI, use@Environment(\.colorScheme)instead. The UIKit callback is for UIKit-based views. - Setting
overrideUserInterfaceStyle = .darkin production code. This is a debugging tool. Shipping it disables the user's system preference for your entire app.
Summary
- Enable dark mode in the iOS Simulator via the Settings app, Xcode's Environment Overrides, or
xcrun simctl ui booted appearance dark. - The
simctlterminal command is the fastest option and is scriptable for CI and automated screenshot testing. - Use UIKit semantic colors (
.label,.systemBackground) and asset catalog variants to support both appearances with minimal code. - In SwiftUI,
@Environment(\.colorScheme)provides reactive appearance tracking. - Override
traitCollectionDidChangein UIKit to handle dynamic appearance switches for non-standard components. - Always test both the initial launch in dark mode and the live transition between modes.
Related reading
- How to use data-binding with Fragment
- How to use Facebook iOS SDK on iOS 10
- How to use generic protocol as a variable type
- How to use Git properly with Xcode?
- How to use fixture-context objects with async specs in ScalaTest?
- How to use JUnit to test asynchronous processes
- How to use icons and symbols from Font Awesome on Native Android Application
- How to use LocalBroadcastManager?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.