Display SRGB value as a background colour to a view

1k views Asked by At

I get an output that says ExtendedSRGB. I have given the output that I got below:

I need to display the SRGB colour in a UIView, so it appears something like:

self.view.backgroundColor = SRGB VALUES

But, unlike RGB values SRGB values range from 0..1. Therefore, how can I display colour.

[ (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; sRGB IEC61966-2.1)] ( 0.745098 0.745098 1 1 )

1

There are 1 answers

1
JaspreetKour On

Try the code below :

let sRGB = CGColorSpace(name: CGColorSpace.sRGB)!
let cgRequiredColor = CGColor(colorSpace: sRGB, components: [0.745098, 0.745098, 1, 1])!
let requiredColor = UIColor(cgColor: cgRequiredColor)
self.view.backgroundColor = requiredColor

As per sRGV values, output is :

enter image description here

For more stuff, Refer to links:

https://codexample.org/questions/779247/how-do-i-compare-2-uicolor-objects-which-are-kcgcolorspacemodelrgb-and-uiextendedsrgbcolorspace-instances-in-logs.c iOS - color on xcode simulator is different from the color on device hex colors in iOS are not accurate

Hope will be helping!