Search code examples
iosobjective-cmathrgba

RGBA decimal notation to arithmetic notation


I have to customize a iOS app and the guideline says:

Please don’t use RGBA values in 0 to 255 decimal notation, but use 0.0 to 1.0 arithmetic notation instead!

For exemple, the default app color #70C7C6 in the guideline is converted to (0.298, 0.792, 0.784, 1.000).

How can I convert other colors? I never knew this arithmetic notation before.


Solution

  • Convert the string hex values into integers, then to get the arithmetic notation divide each value by 255.

    For example "C7" -> 199 -> 199/255. -> 0.78.

    The last value is opacity, which sounds like in your case would always be 1.