如何确定当前设备是否具有支持 P3 的显示器?

tom*_*lum 5 cgcolor uicolor ios swift

如果设备支持,是否可以有条件地选择标准 RGB 颜色或 P3 颜色?

对于 iOS 版本,我想过类似以下的事情:

if #available(iOS 12.0, *) {
    ...
} else {
    ...
}
Run Code Online (Sandbox Code Playgroud)

Mar*_*n R 5

UITraitCollection有一个displayGamut属性,它是一个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
}
Run Code Online (Sandbox Code Playgroud)

您可以查询“主屏幕”

let hasP3Display = UIScreen.main.traitCollection.displayGamut == .P3 
Run Code Online (Sandbox Code Playgroud)

或特定视图的显示(如果使用外部显示器,则可能会有所不同)

let hasP3Display = view.traitCollection.displayGamut == .P3
Run Code Online (Sandbox Code Playgroud)

  • 仅当您 100% 确定用户不会在您的应用中使用任何外部屏幕时才应使用前者。或者,如果您不关心它在外部显示器上的外观。 (2认同)