ColorCompatibility
In iOS 13, Apple introduced a bunch of new system colors (label, systemBackground, etc). These colors dynamically adapt to the preferred user interface style, but these colors aren't available on iOS < 13. ColorCompatibility is an autogenerated library which allows you to specify the system colors as static vars of the ColorCompatibility namespace, instead of UIColor. Using this will make colors "just work" on both iOS 13+ and iOS <= 12. On iOS <= 12, the colors default to Apple's light mode colors.
Please note: there are some system colors (like systemGray
, systemBlue
etc) which have been available before iOS 13. This library does not currently provide fallbacks for these colors - you can use UIColor
to access them. Feel free to submit an issue if you have a use case for including these colors in this library's enum!
E.g.:
import ColorCompatibility
myView.backgroundColor = ColorCompatibility.label
You can read more about this project here.
Example
To run the example project, clone the repo, and run pod install
from the Example directory first.
Requirements
Installation
CocoaPods
ColorCompatibility is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ColorCompatibility'
Swift Package Manager
ColorCompatability is available as a Swift package. To install, add https://github.com/noahsark769/ColorCompatibility.git
as a package dependency in Xcode for a version >= 1.0.1, or as a dependency of another package:
let package = Package(
dependencies: [
.package(url: "https://github.com/noahsark769/ColorCompatibility.git", ...)
]
)
If you'd prefer not to use Cocoapods or SPM, I recommend copy and pasting the ColorCompatibility.swift
code directly into your project. It's only one file
Author
Noah Gilmore, https://noahgilmore.com/blog
License
ColorCompatibility is available under the MIT license. See the LICENSE file for more info.
Contributing
If you see an issue, please report it via the GitHub issues tab. Pull requests are gladly accepted. You can get in touch with me on Twitter at https://twitter.com/noahsark769. Please don't submit PRs which update the library to include colors which have been available before iOS 13 (systemGray
, systemBlue
etc) without first discussing your use case in an issue.
If I don't respond to your issue or PR, feel free to tag me @noahsark769 or mention me on Twitter!