#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
将随机生成的颜色绘制成图片。
iOS 生成随机颜色(UIColor),布布扣,bubuko.com
原文地址:http://blog.csdn.net/shouqiangwei/article/details/25371693