Odd Conversion between UIColor and CGColor

Jake Chasan picture Jake Chasan · Mar 17, 2014 · Viewed 13.5k times · Source

So here are the colors I am trying to convert from UIColor to CGColor:

001385 - R:0 G:19 B:133

ca000b - R:202 G:0 B:11

Here is the Blue vs. iOS's rendering: a:enter image description here b:enter image description here

Here is the Red vs. iOS's rendering: a<code>enter image description here</code> b: enter image description here

Here is the code I am using to convert the colors: Red:

[[UIColor colorWithRed:202 green:0 blue:11 alpha:1] CGColor]

Blue:

[[UIColor colorWithRed:0 green:19 blue:133 alpha:1] CGColor]

Does anyone know what I am doing wrong?

Answer

jervine10 picture jervine10 · Mar 17, 2014

You need to divide the parameters by 255.0. As noted by @Duncan C, ensure you are dividing by 255.0

[[UIColor colorWithRed:202.0/255.0 green:0 blue:11/255.0 alpha:1] CGColor]


[[UIColor colorWithRed:0 green:19/255.0 blue:133/255.0 alpha:1] CGColor]