Is there a way to conditionally select a Standard RGB color or a P3 color if the device supports it?
I thought about something like the following for iOS versions:
if #available(iOS 12.0, *) {
...
} else {
...
}
So what is then Display P3? Very simply put it's a color space within the RGB color model that represents a larger spectrum of colors than the current industry standard sRGB. And most of us have been using sRGB for probably over a decade now, but with display P3 we get a 25 percent larger color space compared to sRGB.
P3 is an RGB color space. DCI-P3 (Digital Cinema Initiative) is used with digital theatrical motion picture distribution (DCDM). Display P3 is a variant developed by Apple Inc. for wide-gamut displays.
UITraitCollection
has a displayGamut
property, which is an enum UIDisplayGamut
@available(iOS 10.0, *)
public enum UIDisplayGamut : Int {
case unspecified // UIKit will not set this anymore, instead a sensible default is chosen based on the device capabilities and settings always
case SRGB
case P3
}
You can query the “main screen”
let hasP3Display = UIScreen.main.traitCollection.displayGamut == .P3
or the display of a specific view (which can be different if an external monitor is used)
let hasP3Display = view.traitCollection.displayGamut == .P3
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