ios - 如何判断颜色格式是RGB还是BGR?

标签 ios swift uicolor cgcolor bgr

让我们假设,

 cgcolor = Any_UIColor.cgColor

现在,如何确定 cgcolorcomponents 是否为 RGB BGR 序列? (组件数量为4)

或者,UIColor 将始终采用 R G B 格式?!

最佳答案

您可以使用CGColorcolorSpace属性。

/* Return the color space associated with `color'. */

@available(iOS 2.0, *)
public var colorSpace: CGColorSpace? { get }

示例:

    let colorspace = UIColor.red.cgColor.colorSpace

CGColorSpaceModel 将为您提供您正在使用的颜色的确切模型。

    let colorspace = UIColor.red.cgColor.colorSpace?.model

引用https://developer.apple.com/documentation/coregraphics/cgcolorspacemodel

关于ios - 如何判断颜色格式是RGB还是BGR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46886993/

相关文章:

ios - 根据按钮选择状态将无法识别的选择器发送到实例

ios - UIKit 问题 - 在 IBOutlet 项目上设置颜色需要花费大量时间

ios - IOS 已经有了 UIColor 为什么还要 CGColor?如果它们不同,那么它们之间有什么区别?

ios - canEvaluatePolicy 函数中的 "switch(error!.code)"在 Swift 3 (Xcode 8) 中不存在

iOS Google OAuth,检索 friend 的电子邮件地址

ios - 为什么 "dict[String(aUint16)] = Int(Date().timeIntervalSince1970 * 1000)"在某些情况下会失败?

swift - 在 swift 中使用 parse 重置密码

swift - 在 Init 中使用 Guard?

ios - UIColor patternImage 与 UIActivityViewController barTintColor 冲突

ios - AVFoundation 音频不会停止静音