skip to Main Content

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

2

Answers


  1. 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
    
    Login or Signup to reply.
  2. for alternative you can add UIView behind and set it as border of you ImageView, it’s easier to set the oppacity

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search