iOS开发——项目实战总结&关于随机量

时间:2021-08-03 05:35:59

关于随机量

随机数

arc4random_uniform(N) + ;

随机字符串

NSString *letter = [NSString stringWithFormat:) + 'a'];

随机颜色

 #import "UIColor+Random.h"
 @implementation UIColor (Random)
 +(UIColor *)randomColor{
     static BOOL seed = NO;
     if (!seed)
     {
         seed = YES;
         srandom(time(NULL));
      }
     CGFloat red = (CGFloat)random()/(CGFloat)RAND_MAX;
     CGFloat green = (CGFloat)random()/(CGFloat)RAND_MAX;
     CGFloat blue = (CGFloat)random()/(CGFloat)RAND_MAX;
     return [UIColor colorWithRed:red green:green blue:blue alpha:1.0f];//alpha为1.0,颜色完全不透明
 }
 @end