How to Use Dark Mode in Simulator iOS 13

How to use dark mode in simulator iOS 13?

In Settings, scroll down to Developer and then Dark Appearance

enter image description here


Update

In addition to the above, there are now many other ways to enable dark appearance in the simulator, as shown in the many great answers below.

• Change Environment Overrides from Xcode (@AshCameron)

• Toggle Appearance A from the Simulator menu (@Shredder2794)

• Update from the command line using xcrun simctl ui booted appearance … (@blackjacx, @tadija)

• Programmatically using overrideUserInterfaceStyle = .dark (@thisIsTheFoxe)

• Specify UIUserInterfaceStyle in your info.plist (@DhavalGevariya)

• Use SimGenie from Curtis Herbert…  https://simgenie.app

How to enable Dark Mode on the Simulator?

There are two ways to activate the dark mode in Xcode 11. Both require you manual steps and are not automatic depending on the time.

1. Environment Overrides

The preferred one is to use the Environment Overrides inside Xcode. When running the App on the simulator in Xcode appears a button in the debugger controls next to 'Debug Memory Graph' and 'Simulate Location'. There you will find a menu for enabling dark mode, as well as choose text size and other accessibility settings.

Dark Mode Settings in Xcode11

2. Simulator Settings

Alternatively you can go inside the Settings App on the simulator:

Settings > Developer > Dark Appearance

How to use dark mode in simulator iOS 12.4?

Dark mode is available in iOS 13.0 and later

How to simulate dark mode on iOS Xcode Swift Playground

You can test it in any view using overrideUserInterfaceStyle

As an example, you can paste this code in a playground to check it (tested in Xcode 11.3.1):

import Foundation
import PlaygroundSupport

extension UIColor {

static var primary: UIColor {
UIColor { trait -> UIColor in
return trait.userInterfaceStyle == .light ? .black : .white
}
}

static var secondary: UIColor {
UIColor { trait -> UIColor in
return trait.userInterfaceStyle == .light ? .white : .black
}
}
}

class DarkModeTestView: UIView {

let label = UILabel(frame: CGRect(x: 0, y: 0, width: 375, height: 300))

override init(frame: CGRect) {
super.init(frame: frame)

backgroundColor = .secondary

label.text = "This text should be displayed in black for light mode and white for dark mode"
label.textColor = .primary
label.numberOfLines = 0

addSubview(label)
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

let testView = DarkModeTestView(frame: CGRect(x: 0, y: 0, width: 375, height: 300))
testView.overrideUserInterfaceStyle = .dark // Change here .light or .dark

PlaygroundPage.current.liveView = testView

Opting out of Dark Mode with iOS 15 using Xcode 13

For anyone else who lands here using Xcode 13. Here are the steps

  1. First, click on your project.

enter image description here


  1. Click on "Info"

enter image description here


  1. Click on the "+" on any Key to open a new K,V pair and add "Apperance" -> set value to "Light"

enter image description here


  1. Double check it exists in "Build Settings" under Info.plist Values under "User Interface Style" -> Light

enter image description here

Why doesn't my iOS app disable dark mode?

Simply you can add a new key UIUserInterfaceStyle in your app info.plist (Notes: Xcode 12 and above has renamed to Appearance) and set its value to Light or Dark. this will override the app default style to the value you provide.

so you don't need to bother about having it anywhere else



Related Topics



Leave a reply



Submit