Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save simrandotdev/ac7162a2b34875418736bddf232b071a to your computer and use it in GitHub Desktop.

Select an option

Save simrandotdev/ac7162a2b34875418736bddf232b071a to your computer and use it in GitHub Desktop.
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