in Tricks

Cool UIColor category

When working with graphic designers for interface design you get a lot of color codes like #17d3ff and #555 (basically HTML color codes) and using UIColor main methods could be a pain.

To set color #17d3ff using Obj-c

UIColor* color = [UIColor colorWithRed:0x17/255.0f 
                          green:0xd3/255.0f 
                          blue:0xff/255.0f 
                          alpha:1.0f];

It’s a mouthful.

Luckily nicklockwood has created an great Obj-c category for these specific needs. It has a lot of utility methods added like colorWithString which takes an HTML color codes directly

        UIColor* color = [UIColor colorWithString:@"#17d3ff"];

Much much better, and it also keeps the readability of your design code much easier to follow.

Try it here.

I have also made a fork that includes some more utility functions like “darker/lighter” shorthands.

Try the fork here