Created
August 18, 2019 14:16
-
-
Save prafullakumar/f6420942011ee5f0dc37cda5b3fd4c0c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class ViewController: UIViewController { | |
var userInterfaceStyle: UIUserInterfaceStyle? | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view. | |
userInterfaceStyle = self.traitCollection.userInterfaceStyle | |
setupUI() | |
} | |
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | |
super.traitCollectionDidChange(previousTraitCollection) | |
//update user interface | |
setupUI() | |
} | |
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { | |
// Trait collection will change. Use this one so you know what the state is changing to. | |
userInterfaceStyle = newCollection.userInterfaceStyle | |
} | |
private func setupUI() { | |
switch userInterfaceStyle { | |
case .dark: | |
// User Interface is Dark | |
() | |
case .light: | |
// User Interface is Light | |
() | |
case .unspecified: | |
//your choice | |
() | |
case .none: | |
// Optional default case new introduction | |
() | |
@unknown default: | |
() | |
//Switch covers known cases, but 'UIUserInterfaceStyle' may have additional unknown values, possibly added in future versions | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment