Skip to content

Instantly share code, notes, and snippets.

@andrey-str
Created April 12, 2016 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrey-str/3a52ef9360141cc64e199caba98e18d5 to your computer and use it in GitHub Desktop.
Save andrey-str/3a52ef9360141cc64e199caba98e18d5 to your computer and use it in GitHub Desktop.
Random UI/SK/NSColor snippet(obj-c)
- (UIColor*) randomColor{
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];
return color;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment