Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default color space for UIColor?

Tags:

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.

How to pick the right RGB values for the Display P3 color space. enter image description here

like image 790
Vladimír Slavík Avatar asked May 14 '15 11:05

Vladimír Slavík


People also ask

What is the best color space settings?

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.

What is standard color space?

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.

What color space does Apple use?

iPhone uses sRGB color space.

What is UIColor?

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.


2 Answers

TL;DR

iOS uses Extended sRGB as its default.

Detailed Explanation

This can easily be verified via the debugger in Xcode:

  • put a breakpoint anywhere in your code,
  • when lldb comes up, type po UIColor.red,
  • the above command will return 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.

like image 195
Yohst Avatar answered Oct 28 '22 00:10

Yohst


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.

like image 35
vsanthanam510 Avatar answered Oct 27 '22 23:10

vsanthanam510