If you are in the market for a color library, you’ll find many. I needed to convert a hex color into a UIColor. Let’s try with Artsy purple. Rumor is that it was inspired by Kenny Scharf’s “Purple”.
Gross. One of the bigger problems with this code is that it creates a different color on 32-bit vs. 64-bit as a result of a non-integer division. Yes, we do write tests that compare snapshot images with ios-snapshot-testcase and those created on 32-bit simulators will fail on 64-bit ones. Also, someone with good vision will notice that our brand purple isn’t quite the same purple :)
What we want is to convert the color from its hex color.
What happens in every developer’s mind is a mystery to me: seems like everyone has rolled out their own conversion macro or library. I have counted no less than twelve implementations, two in our own codebase. This is why I personally don’t like the approach taken by the Apple and Microsoft, which only expose the lowest level API possible as a general rule.
The library to end this madness is EDColor. It also supports HSL, HSB, CIELAB and even Crayola crayon colors.
I contributed the iOS7 colors implementation from here, and found two bugs while writing tests. So, if you find another color library, you should merge it in as well. I reached out to Caran d’Ache to get their color palette, but didn’t get a reply.