diff --git a/ColorUtils/ColorUtils.h b/ColorUtils/ColorUtils.h old mode 100644 new mode 100755 index e33ff09..f7abb2d --- a/ColorUtils/ColorUtils.h +++ b/ColorUtils/ColorUtils.h @@ -66,6 +66,9 @@ - (instancetype)colorWithBrightness:(CGFloat)brightness; - (instancetype)colorBlendedWithColor:(UIColor *)color factor:(CGFloat)factor; ++ (instancetype)randomColor; ++ (instancetype)randomColorWithAlpha:(CGFloat)alpha; + @end diff --git a/ColorUtils/ColorUtils.m b/ColorUtils/ColorUtils.m old mode 100644 new mode 100755 index 0f7bd48..d79b6bf --- a/ColorUtils/ColorUtils.m +++ b/ColorUtils/ColorUtils.m @@ -385,4 +385,22 @@ - (instancetype)colorBlendedWithColor:(UIColor *)color factor:(CGFloat)factor alpha:fromRGBA[3] + (toRGBA[3] - fromRGBA[3]) * factor]; } ++ (instancetype)randomColor +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + srandom((unsigned int)time(NULL)); + }); + + return [UIColor colorWithRed:random()%256/255.0 + green:random()%256/255.0 + blue:random()%256/255.0 + alpha:1]; +} + ++ (instancetype)randomColorWithAlpha:(CGFloat)alpha +{ + return [[UIColor randomColor] colorWithAlphaComponent:alpha]; +} + @end