Random Colors on iOS

A quick tip that I have to look up every time I use it. To generate nice random colors, use the HSV representation. Take random values for hue, and fixed numbers for saturation and value. This gives colors that work together, without looking too random.

[[UIColor colorWithHue:drand48() saturation:0.5
brightness:0.95 alpha:0.5] setFill];

Random color filled polygons

Remember to use setStroke if you need the outline of the shape. This article has more information, including better spaced colors. Thanks to NSHipster for the random number methods.