Skip to content

Instantly share code, notes, and snippets.

@Budyn
Last active January 30, 2020 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Budyn/5e78abb0aac0cde6d1049a5e9d1c6c64 to your computer and use it in GitHub Desktop.
Save Budyn/5e78abb0aac0cde6d1049a5e9d1c6c64 to your computer and use it in GitHub Desktop.
Dynamic colors in Swift. Use it for dark mode.
extension UIColor {
static func system(light: UIColor, dark: UIColor) -> UIColor {
guard #available(iOS 13, *) else { return light }
return UIColor { traits in
switch traits.userInterfaceStyle {
case .dark: return dark
case .light: return light
case .unspecified: return light
@unknown default: return light
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment