Last active
January 30, 2020 06:14
-
-
Save Budyn/5e78abb0aac0cde6d1049a5e9d1c6c64 to your computer and use it in GitHub Desktop.
Dynamic colors in Swift. Use it for dark mode.
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
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