生成随机色

UIColor-Random.h

 

#import <UIKit/UiKit.h>

@interface UIColor(Random)

+(UIColor *)randomColor;

@end

 

UIColor-Random.m

 

#import "UIColor-Random.h"

@implementation UIColor(Random)

+(UIColor *)randomColor {
	static BOOL seeded = NO;
	if(!seeded) {
		seeded = YES;
		srandom(time(NULL));
	}
    CGFloat red = (CGFloat)random()/(CGFloat)RAND_MAX;
    CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX;
    CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX;
    return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];
}

@end

你可能感兴趣的:(ios,iPhone)