Created
July 20, 2020 06:54
-
-
Save simrandotdev/ac7162a2b34875418736bddf232b071a 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
| lass UIViewBasicsController: UIViewController { | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| self.view.backgroundColor = UIColor(named: "myColor") | |
| // Get the color value of system Colors through TraitCollection | |
| let yellow = UIColor.systemYellow | |
| let light = UITraitCollection(userInterfaceStyle: .light) | |
| let dark = UITraitCollection(userInterfaceStyle: .dark) | |
| let yellowLight = yellow.resolvedColor(with: light) | |
| let yellowDark = yellow.resolvedColor(with: dark) | |
| print(yellowLight) | |
| print(yellowDark) | |
| } | |
| override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { | |
| super.traitCollectionDidChange(previousTraitCollection) | |
| // Change custom color color Theme change | |
| if previousTraitCollection?.hasDifferentColorAppearance(comparedTo: self.traitCollection) ?? true { | |
| self.view.backgroundColor = UIColor(named: "myColor") | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment