How to set profile Border opacity ?
How to set transparent for having opacity of border color with .white of 50% opacity.
profileView.layer.borderWidth = 3.0
profileView.layer.borderColor = UIColor.white.cgColor
CodePudding user response:
Use withAlphaComponent
:
profileView.layer.borderColor = UIColor.white.withAlphaComponent(0.5).cgColor
or:
profileView.layer.borderColor = UIColor.white.cgColor.copy(alpha: 0.5)
Obviously you can choose whatever alpha value you want in the range 0.0 to 1.0.
Or in this case you can use:
profileView.layer.borderColor = UIColor(white: 1.0, alpha: 0.5).cgColor
CodePudding user response:
To set the opacity of a border on an ImageView in Swift, you can use the alpha property of the CALayer that is associated with the ImageView. Here's an example:
let imageView = UIImageView()
// set the border color and width
imageView.layer.borderColor = UIColor.black.cgColor
imageView.layer.borderWidth = 2
// set the border opacity
imageView.layer.borderColor = imageView.layer.borderColor?.withAlphaComponent(0.5)
In the code above, we first set the border color and width for the ImageView, then we set the opacity by using the withAlphaComponent(_:) method of UIColor to create a new color with the desired opacity. The alpha value should be a number between 0 (fully transparent) and 1 (fully opaque).
CodePudding user response:
for alternative you can add UIView behind and set it as border of you ImageView, it's easier to set the oppacity