I am setting a border to my layer
by adding the following line of code:
[self.avatar.layer setBorderColor:[UIColor whiteColor].CGColor];
How can I change the alpha on just the border and not the avatar
object as well?
Use UIColor
's +colorWithWhite:alpha:
[self.avatar.layer setBorderColor:[UIColor colorWithWhite:1.0f alpha:0.5f].CGColor];
If you need a color other than white, use +colorWithRed:green:blue:alpha:
as already mentioned by user3386109.
For Swift-3 Version
let opacity:CGFloat = 0.6
let borderColor = UIColor.white
self.view.layer.borderColor = borderColor.withAlphaComponent(opacity).cgColor
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