iOS randomColor (随机颜色)

使用方法:导入头文件,调用

self.backgroundColor= [UIColorrandomColor];

.h 文件

#import  

@interfaceUIColor (additions)

+ (UIColor*)randomColor;

@end

.m 文件

#import"UIColor+additions.h"

@implementationUIColor (additions)

+ (UIColor*)randomColor

{

CGFloathue = (arc4random() %256/256.0);

CGFloatsaturation = (arc4random() %128/256.0) +0.5;

CGFloatbrightness = (arc4random() %128/256.0) +0.5;

UIColor*color = [UIColorcolorWithHue:huesaturation:saturationbrightness:brightnessalpha:1];

returncolor;

}

@end

你可能感兴趣的:(iOS randomColor (随机颜色))