Skip to content

Instantly share code, notes, and snippets.

@masbog
Forked from kylefox/color.m
Created September 17, 2012 08:41
Show Gist options
  • Save masbog/3736218 to your computer and use it in GitHub Desktop.
Save masbog/3736218 to your computer and use it in GitHub Desktop.
Generate a random color (UIColor) in Objective-C
CGFloat hue = ( arc4random() % 256 / 256.0 ); // 0.0 to 1.0
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from white
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0, away from black
UIColor *color = [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment