Last active
November 4, 2021 11:14
-
-
Save jamesujeon/136ddde3ccf2e3e0fb175807c330e8d7 to your computer and use it in GitHub Desktop.
Change user interface style by inverting it
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
extension AppDelegate { | |
func changeUserInterfaceStyle() { | |
guard let window = window else { return } | |
if window.overrideUserInterfaceStyle == .unspecified { | |
window.overrideUserInterfaceStyle = UIScreen.main.traitCollection.userInterfaceStyle == .light ? .dark : .light | |
} else { | |
window.overrideUserInterfaceStyle = window.overrideUserInterfaceStyle == .light ? .dark : .light | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment