I can not find an article or a document describing which color space should be used for RGB values when initialising an instance from UIColor class.
The article Getting the right colors in your ios app says we should use Generic RGB. On the other hand, I have found several posts saying that we should definitely use sRGB on iOS.
It seems the default color space is sRGB as written here in CGColorSpace Reference
There is a new color space called "Display P3" used in the iPad Pro and iPhone 7. The profile in the existing image resources has to be converted to the Display P3. For Digital Color Meter app the P3 profile has to be selected in order to get "Display P3" RGB values. See the screenshot.
sRGB is an RGB color space that was developed by Microsoft and HP for digital use. It's the most appropriate color space for computer screens and other digital devices, like tablets and smartphones.
When defining a color space, the usual reference standard is the CIELAB or CIEXYZ color spaces, which were specifically designed to encompass all colors the average human can see.
iPhone uses sRGB color space.
UIColor provides a list of class properties that create adaptable and fixed colors such as blue, green, purple, and more. UIColor also offers properties to specify system-provided colors for UI elements such as labels, text, and buttons.
iOS uses Extended sRGB as its default.
This can easily be verified via the debugger in Xcode:
po UIColor.red
,UIExtendedSRGBColorSpace 1 0 0 1
as of iOS 11, Xcode 9.2.This color space can use the same sRGB values without a color change but at the same time permits RGB values to go negative as well as larger than 1.0 to express colors outside the sRGB color space (i.e. the extended sRGB color space).
There is a WWDC video, Working with Wide Color, from 2016 that explains this phenomenon nicely (go to 8:35).
So if you use sRGB colors in your app you should be good to go even for e-sRGB displays. Of course, if you need one of those specific colors outside the sRGB gamut, you will need to use the e-sRGB color space.
I wrote a blog post that explains this in detail:
http://www.vsanthanam.com/writing/2017/7/6/colors-in-ios-ensuring-consistency-between-designs-interface-builder-and-uicolor
Essentially, while Sketch uses a custom color picker that assumes sRGB color components, Xcode's color pick does not.
UIColor's most common factory method +colorWithRed:green:blue:alpha: assumes the sRGB Color Space (Extended sRGB if linked with iOS 10.x), but it also has another factory method, colorWithDisplayP3Red:green:blue:alpha: which will take in your Display P3 color space RGBA components, but stores them internally as translated values with a reference to the sRGB color space.
As always, take a look at Apple's documentation on UIColor for more info:
https://developer.apple.com/documentation/uikit/uicolor?changes=latest_minor
Interestingly enough, AppKit's UIColor counterpart, NSColor, supports way more flexibility with more available factory methods (including one designed with a custom color space specifically to mimic UIColor's +colorWithRed:green:blue:alpha: behavior). I'm not sure why UIColor is more limited.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With