Skip to content

Instantly share code, notes, and snippets.

@jamesujeon
Last active November 4, 2021 11:14
Show Gist options
  • Save jamesujeon/136ddde3ccf2e3e0fb175807c330e8d7 to your computer and use it in GitHub Desktop.
Save jamesujeon/136ddde3ccf2e3e0fb175807c330e8d7 to your computer and use it in GitHub Desktop.
Change user interface style by inverting it
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