Ajith's Blog

I occasionally blog here. Primarily on Swift and iOS development, but also some thoughts about languages, tools, and techniques in software development.Checkout my website.

If you are not using Xcode 11 or later (i,e iOS 13 or later SDK), your app has not automatically opted to support dark mode. So, there’s no need to opt out of dark mode.
If you are using Xcode 11 or later, the system has automatically enabled dark mode for your app.
There are two approaches to disable dark mode depending on your preference. You can disable it entirely or disable it for any specific window, view, or view controller.

Disable Dark Mode Entirely for your App

You can disable dark mode by including the UIUserInterfaceStyle key with a value as Light in your app’s Info.plist file.

Top iOS Development Resources To Follow

This ignores the user’s preference and always applies a light appearance to your app.

Disable dark mode for Window, View, or View Controller

You can force your interface to always appear in a light or dark style by setting the overrideUserInterfaceStyle property of the appropriate window, view, or view controller.

View controllers:
override func viewDidLoad() {
    /* view controller’s views and child view controllers
     always adopt a light interface style. */
    overrideUserInterfaceStyle = .light
// The view and all of its subviews always adopt light style.
youView.overrideUserInterfaceStyle = .light
/* Everything in the window adopts the style,
 including the root view controller and all presentation controllers that
 display content in that window.*/
window.overrideUserInterfaceStyle = .light

Note: Apple strongly encourages to support dark mode in your app. So, you can only disable dark mode temporarily.

Read more from Apple’s documentation here: Choosing a Specific Interface Style for Your iOS App

This post was originally written to answer a Stackoverflow question.

Thanks for reading!✨
If you found my work helpful, buy me a cup of coffee! I will appreciate it a lot.

Buy Me A Coffee