![]() Hopefully this makes your app's transition to dark mode easier! When we drop iOS 12 support, cleaning this up will be as simple as replacing every instance of ColorCompatibility with UIColor □.Since everything is a computed var, we never pre-store colors, which means that when the user switches color scheme, our app will automatically adapt as the trait collection changes □.This code will compile on iOS 13+, iOS 12 and earlier, and Catalyst ✅.Note: we can't use for these checks, since it doesn't provide a way to check if the current environment is less than a specific app version. We can then use ColorCompatibility it to set any colors we need. This means we'll probably be doing a lot of things like this, using Swift's #available syntax: if #available ( iOS 13, * ) These new colors are all well and good, but most of us with existing apps will still be supporting devices with iOS 12 or lower, at least for a while. (Skip to the bottom if you'd like to see a list of the new colors.) Compatibility However, even system colors that have been around for a while (like systemRed) have become dynamic in iOS 13 - they might actually be different colors in dark mode vs light mode. IOS 13 has 23 new element colors ( label etc) and one new standard color ( systemIndigo). Standard Colors ( systemIndigo, systemGra圓, etc).Label is only one example: there are 24 new color scheme agnostic UIColors available in iOS 13+. ![]() In iOS 13+, it's better to use the new system color which will respect the user's color scheme preference: label. blackīut in Dark Mode, the background will also be black, which means the text won't be visible. On iOS 12 and older, you might have a label you want to make black, and it would work just fine - in fact, black was the default color for UILabels. One of the changes that makes adopting Dark Mode so easy is the new system colors API from UIColor. There are some significant changes to UIKit in order to support this - many of them are detailed in the talk Implementing Dark Mode on iOS which I'd highly recommend watching. This has now been fixed, but I'd recommend looking at the ColorCompatibility library if you're interested in using it in your own projects.Īt WWDC 2019, Apple announced that Dark Mode would be supported on iOS 13. Update (): A previous version of this post included the wrong color values in one of the example code blocks. Update (): In order to better support bug reporting on ColorCompatibility, I've released it as a library. These have been updated - the defaults are now the light mode colors which are being used in production in Trestle and CIFilter.io. Update (): A previous version of this post included the wrong default colors in the ColorCompatibility code at the bottom of the post. I also updated a reference to Mac Catalyst. The code has been updated, and the tables in this post still list all system and element colors - even those which have been available for a while, since they're different in dark mode vs light mode. It also contained unnecessary availability checks in the code at the bottom (system colors like red, blue etc have been available since iOS 7). Update (): The original version of this post included systemBrown, a color which was removed in the Xcode 11 GM. Update (): The original version of this post featured the wrong colors in the ColorCompatibility enum at the end of the post.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |