How do I determine if current device does have a P3 capable display?

554 views Asked by At

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 {
    ...
}
1

There are 1 answers

1
Martin R On BEST ANSWER

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