I try to get a random color for UILabel...
- (UIColor *)randomColor { int red = arc4random() % 255 / 255.0; int green = arc4random() % 255 / 255.0; int blue = arc4random() % 255 / 255.0; UIColor *color = [UIColor colorWithRed:red green:green blue:blue alpha:1.0]; NSLog(@"%@", color); return color; }
And use it:
[mat addAttributes:@{NSForegroundColorAttributeName : [self randomColor]} range:range];
But color is always black. What is wrong?
There is no way to do this using CSS only. CSS doesn't support logical statements because CSS is purely deterministic (there is nothing like array etc in CSS). We can use client-side JavaScript to select a random color from the array.
[UIColor colorWithHue:drand48() saturation:1.0 brightness:1.0 alpha:1.0];
or in Swift:
UIColor(hue: CGFloat(drand48()), saturation: 1, brightness: 1, alpha: 1)
Feel free to randomise or adjust saturation and brightness to your liking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With