Skip to content

Instantly share code, notes, and snippets.

@fangj
Forked from r3econ/UIColor+Random.h
Last active August 29, 2015 14:09
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 fangj/5da8fa767f7046c708bd to your computer and use it in GitHub Desktop.
Save fangj/5da8fa767f7046c708bd to your computer and use it in GitHub Desktop.
@interface UIColor (Random)
+ (UIColor *)randomColor;
@end
#import "UIColor+Random.h"
@implementation UIColor (Random)
+ (UIColor *)randomColor
{
// 0.0 to 1.0
CGFloat hue = ( arc4random() % 256 / 256.0 );
// 0.5 to 1.0, away from white
CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5;
// 0.5 to 1.0, away from black.
CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5;
return [UIColor colorWithHue:hue
saturation:saturation
brightness:brightness
alpha:1];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment