Last active
August 29, 2015 14:18
-
-
Save hechen/20b702b962ef29604ee6 to your computer and use it in GitHub Desktop.
Generate random Color using category based UIColor
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
// | |
// UIColor+RandomColor.h | |
// ViewImage | |
// | |
// Created by hechen on 15/4/8. | |
// Copyright (c) 2015年 hechen. All rights reserved. | |
// | |
#import <UIKit/UIKit.h> | |
@interface UIColor(RandomColor) | |
+(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
// | |
// UIColor+RandomColor.m | |
// ViewImage | |
// | |
// Created by hechen on 15/4/8. | |
// Copyright (c) 2015年 hechen. All rights reserved. | |
// | |
#import "UIColor+RandomColor.h" | |
@implementation UIColor(RandomColor) | |
+ (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 | |
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