iOS 13 introduced semantic UIColor
s like .label
, .systemBackground
, etc. that will automatically adapt to light or dark mode. These colors aren't available to earlier versions of iOS, however, so to use them you'd have to litter your code with if #available
everywhere.
To fix this, I generated a file that includes all of the new iOS 13 colors with light-themed fallbacks to support older iOS versions. To use it, just reference colors using the SystemColor
type instead of UIColor
and you should be good to go!
Add via Swift Package Manager:
.package(url: "SystemColor", .branch("master"))
self.view.backgroundColor = SystemColor.systemBackground
self.label.textColor = SystemColor.label
// etc.
I used a script to iterate over all of the new colors mentioned in the documentation, extracted their RGB values, and generated a Swift file with this information. You can check out the script in the generator.swift
file.
If I missed a color or Apple adds more, add them to the file and submit a pull request!