I am currently doing this:
UIColor *myColor = [UIColor clearColor];
This is great but i would like to specify a certain alpha of "myColor". How would i do so?
If you have an existing color, you can return a new one with a specified alpha, like this:
- (void)setBackgroundColor:(UIColor *)color { self.backgroundColor = [color colorWithAlphaComponent:0.3f]; }
[UIColor clearColor]
is, how should I put it?, clear!
It is a convenience class method returning a UIColor
with alpha at zero.
If you want a color with a fractional amount of transparency:
+ (UIColor *)colorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
Or one of the other UIColor
class methods.
You can use colorWithWhite:alpha
like so:
[UIColor colorWithWhite:1.0 alpha:0.5];
Or if you want a specific color:
[UIColor colorWithRed:1.0 green:1.0 blue:0.3 alpha:0.72];
Check out the docs.
For Swift you can use:
UIColor.black.withAlphaComponent(0.5)
Or RGB Colors:
UIColor(red: 0/255.0 , green: 0/255.0 , blue: 0/255.0 , alpha: 0.5)
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