Last active
August 29, 2015 13:57
-
-
Save r3econ/9772706 to your computer and use it in GitHub Desktop.
UIColor category for creating a random color.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface UIColor (Random) | |
+ (UIColor *)randomColor; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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