Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ColorUtils/ColorUtils.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
- (instancetype)colorWithBrightness:(CGFloat)brightness;
- (instancetype)colorBlendedWithColor:(UIColor *)color factor:(CGFloat)factor;

+ (instancetype)randomColor;
+ (instancetype)randomColorWithAlpha:(CGFloat)alpha;

@end


Expand Down
18 changes: 18 additions & 0 deletions ColorUtils/ColorUtils.m
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -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