🗓 Oct 8, 2021⏳ 1 minutes

How to force light or dark mode in SwiftUI

sleep
Photo by Kyle Johnson on Unsplash



Since iOS 13 we can override system behaviour for dark / light mode using following property.

overrideUserInterfaceStyle = .dark

In UIKit, you can apply this property to any UIView, UIViewController or UIWindow, and the change applies to all elements down the hierarchy of views.

In SwiftUI, the same can be accomplished using following viewModifier for views:

.colorScheme(.dark)

What if we just want to force one, light or dark style to whole app? All we have to do it add new property Appearance (formerly known as User Interface Style) for our Target in Info.plist applying one of the values = Light or Dark:

how-to-force-light-mode-in-appearance
Tagged with: