1

Lets assume ,

 cgcolor = Any_UIColor.cgColor

Now , how can I determine whether components of cgcolor is in RGB or BGR sequence ? (Number of components is 4)

Or, UIColor will always be in R G B format ?!

roy
  • 6,685
  • 3
  • 26
  • 39
  • My guess is 4 components is a CMYK color space. If you accept any kind of color space as input, the components could be in any order. In the extremely general case you may even have 3 shades of red as components. Is it possible to convert the color to a known color space first? – Mats Oct 23 '17 at 10:31
  • @Mats what if RGB and Alpha makes 4 ? – roy Oct 23 '17 at 10:34
  • I guess RGBA used for `cgColor` – Jack Oct 23 '17 at 10:38
  • @Roy I mistook it for the number of components on the color space. I apologise for the confusion. – Mats Oct 23 '17 at 12:21

1 Answers1

1

You can use colorSpace property of CGColor.

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

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

Example:

    let colorspace = UIColor.red.cgColor.colorSpace

CGColorSpaceModel will give you the exact model of the color that you are using.

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

Refer to https://developer.apple.com/documentation/coregraphics/cgcolorspacemodel

PGDev
  • 23,751
  • 6
  • 34
  • 88