Disabling Dark Mode in iOS Apps with Swift

Customizing Dark Mode Settings in Swift

Vikram Kumar
3 min readNov 8, 2023

Dark Mode is a popular feature in iOS that allows users to change the appearance of their apps to a darker color scheme. It can be easier on the eyes in low-light environments and extend the battery life of OLED-equipped devices. However, there are cases where you might want to disable Dark Mode in your iOS app, such as when your app's design is better suited for a light mode. In this article, we will explore how to disable Dark Mode in iOS using Swift.

Photo by Daniel Korpai on Unsplash

Enabling and Disabling Dark Mode

In iOS, you can enable or disable Dark Mode for your app by adjusting its appearance preferences. The appearance preferences are part of the UIUserInterfaceStyle enumeration, which has two options: .light for light mode and .dark for Dark Mode. By setting the preferred style for your app, you can control whether it uses Dark Mode or not.

Here’s how you can disable Dark Mode in your iOS app using Swift:

Step 1: Open your project

Open your Xcode project where you want to disable Dark Mode.

Step 2: Set the preferred user interface style

To disable Dark Mode in your entire app, you need to set the preferred user interface style in your app’s Info.plist file.

  1. Xcode, locate the Info.plist file for your project. It's typically located in the project navigator under your target.
  2. Right-click on a blank area in the Information Property List and select "Add Row" to add a new property.
  3. In the newly added row, set the key to “UIUserInterfaceStyle” and the value to “Light.”
<key>UIUserInterfaceStyle</key>
<string>Light</string>
Info.plist

This will set the preferred user interface style for your app to light mode, effectively disabling Dark Mode throughout your app.

Step 3: Testing

It’s essential to test your app to ensure that Dark Mode has been disabled successfully. Run your app on a simulator or a physical device. You should now see your app using the light mode appearance.

Bonus Tip: iOS Simulator shortcut to toggle between light and dark mode

⌘ (command) + ⇧ (shift) + A

Disabling Dark Mode for Specific Views

If you want more granular control over Dark Mode in your app, you can disable it for specific views or view controllers. To do this, you can override the overrideUserInterfaceStyle property of a view controller to set its preferred style.

Here’s how you can disable Dark Mode for a specific view controller using Swift:

import UIKit

class MyViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()

// Disable Dark Mode for this view controller
overrideUserInterfaceStyle = .light
}
}

In the code above, we’ve created a custom UIViewController class and overridden the overrideUserInterfaceStyle property to set it to .light. This will ensure that this specific view controller always uses light mode, regardless of the system-wide appearance setting.

Conclusion

Dark Mode is a popular feature in iOS, but there are cases where you might want to disable it for your app. By adjusting the preferred user interface style in your app’s Info.plist or by overriding the overrideUserInterfaceStyle property for specific view controllers, you can have more control over Dark Mode in your iOS app. Whether you disable it entirely or for specific parts of your app, Swift provides the tools to give your users the experience you desire.

--

--

Vikram Kumar

I am Vikram, a Senior iOS Developer at Matellio Inc. focused on writing clean and efficient code. Complex problem-solver with an analytical and driven mindset.