• Stars
    star
    106
  • Rank 325,871 (Top 7 %)
  • Language
    Swift
  • License
    MIT License
  • Created about 5 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Use iOS 13+ system colors while defaulting to light colors on iOS <=12

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.

Version License Platform

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 👍

Notes

When dropping in UIColor in place of ColorCompatibility when your app drops support for iOS 12, it's not strictly guaranteed that all colors behave the same way: for example, in iOS 13, system colors adapt to display differently when they're in an "elevated" context, like the background color of a view controller presented modally. For more information on elevated colors, see the Human Interface Guidelines on Dark Mode.

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!

More Repositories

1

cifilter.app

CIFilter documentation and examples project
Swift
248
star
2

NGUIButtonInsetsExample

Example app which shows how UIButton insets work
Swift
219
star
3

CatalystPlayground

An example project demonstrating Mac Catalyst features
Swift
104
star
4

NGSystemColorComparison

A small app which shows the system UIColors and generates code for backwards compatibility
Swift
64
star
5

sfsymbols.com

SF Symbols reference site
JavaScript
62
star
6

NGSwiftUITableCellSizing

Demonstrates issues with SwiftUI views inside self sizing UITableViewCells
Swift
45
star
7

NGPopoverForceResizeTest

A UIKit interaction where two view controllers are presented in a nav controller as a popover
Swift
31
star
8

SFSymbolsGenerator

The sample app which generates images for sfsymbols.com
Swift
14
star
9

xcodeproj-sort-pre-commit-hook

A pre-commit hook that sorts your xcodeproj file
Ruby
13
star
10

seemorejs

A lightweight, simple jQuery plugin for partial collapse and expand of html.
CoffeeScript
10
star
11

NGCAMetalLayerAnimationExample

Example of animating changes in a CAMetalLayer
Swift
8
star
12

NGAppKitSystemImages

Sample app showing AppKit system images
Swift
5
star
13

MetalByExampleExamples

Example app for working through examples from Metal By Example
Swift
4
star
14

NGXCTestNotFoundExample

Issue with XCTest.h not being found on Xcode 12 beta 1. Apple feedback: FB7775577
Objective-C
4
star
15

noahgilmore.com

My personal website/blog
MDX
4
star
16

NGUIViewLayerBackgroundColorTest

Example app which demonstrates that layers which back views do not have implicit animations by default
Swift
2
star
17

simplegit

A python module for simple interaction with git via subprocess
Python
2
star
18

sonar-testing-example-projects

Collection of example projects using Sonar (fbsonar.com)
Objective-C
2
star
19

SwiftIndiaDemo

Demo for Swift India 2019: Using AppKit bundles to customize a Catalyst app
Swift
2
star
20

NGConditionalModifierIssue

Demonstrates an issue with conditional modifiers in SwiftUI on macOS
Swift
1
star
21

quicktour.js

Intuitive, pretty jQuery website tours.
CoffeeScript
1
star
22

NGTextViewCustomBackgroundDrawingExample

Example of how to draw a custom border around part of text in an NSTextView
Swift
1
star
23

NGSwiftUITextAttachmentDemo

Demo of using arbitrary SwiftUI views as NSTextView attachments
Swift
1
star
24

DefaultDict

A Swift microframework for for dictionaries with default values
Swift
1
star
25

dotfiles

For easy setup of new machines
Shell
1
star
26

tile-world-mac

Mac update for Tile World
C
1
star
27

gatsby-json-pages-example

Example of how to generate Gatsby.js pages from a json file
CSS
1
star
28

NGUIStackViewAnimationTest

An example of using UIStackView animations
Swift
1
star
29

NGSwiftUIRelativeDateTimeFormatterExample

Example code for a blog post about how to use RelativeDateTimeFormatter in SwiftUI
Swift
1
star
30

resources

A collection of useful pages to refer to for various technologies. Anything I always find myself coming back to for reminders. Cheat sheets, tutorials, etc.
1
star
31

sketch-preset-icons-generator

Python scripts to generate Sketch export presets for icons
Python
1
star
32

userdefaults-set-nil-example

Example demonstrating the behavior of UserDefaults.set(nil, forKey:) in iOS 10
Swift
1
star