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



将随机生成的颜色绘制成图片。





iOS 生成随机颜色(UIColor),布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!