iOS 生成随机颜色(UIColor)
时间:2014-05-09 13:57:22
收藏:0
阅读:477
#import <UIKit/UIKit.h>
@interface UIColor (RandomColor)
+(UIColor *) randomColor;
@end
#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
将随机生成的颜色绘制成图片。
评论(0)