title: How to set gradient color to UIImageView border
body: <p>How to apply gradient color to UIImageView border color. What i tried is</p>
  
  <pre><code>let gradient: CAGradientLayer = CAGradientLayer()
  
      let color0 = UIColor(red:0.0/255, green:0.0/255, blue:0.0/255, alpha:0.0).CGColor
      let color1 = UIColor(red:0.0/255, green:0.0/255, blue: 0.0/255, alpha:0.71).CGColor
  
      gradient.colors = [color0, color1]
      gradient.locations = [0.0 , 1.0]
      gradient.frame =  CGRect(x: 0.0, y: 80.0, width: self.imgProfile.frame.size.width, height: self.imgProfile.frame.size.height-35)
  
      self.imgProfile.layer.insertSublayer(gradient, atIndex: 0)
  </code></pre>
  
  <p>This is what required</p>
  
  <p><a href="https://i.stack.imgur.com/MeFol.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MeFol.png" alt="enter image description here"></a></p>
  
  <p>Please guide, thanks</p>
  
  <p>Update:</p>
  
  <p>Tried this way</p>
  
  <pre><code>let gradient = CAGradientLayer()
      gradient.frame =  CGRect(origin: CGPointZero, size: self.imgPeopleProfile.frame.size)
      gradient.colors = [UIColor.blueColor().CGColor, UIColor.greenColor().CGColor]
  
      let shape = CAShapeLayer()
      shape.lineWidth = 2
      shape.path = UIBezierPath(rect: self.imgPeopleProfile.bounds).CGPath
      shape.strokeColor = UIColor.blackColor().CGColor
      shape.fillColor = UIColor.clearColor().CGColor
      gradient.mask = shape
  
      imgPeopleProfile.layer.cornerRadius = imgPeopleProfile.frame.size.width / 2
      imgPeopleProfile.clipsToBounds = true
      self.imgPeopleProfile.layer.addSublayer(gradient)
  </code></pre>
  
  <p>It gives <a href="https://i.stack.imgur.com/fDUX4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fDUX4.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/pWV4U.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pWV4U.png" alt="enter image description here"></a></p>