Skip to content

Instantly share code, notes, and snippets.

@SergLam
Created April 17, 2019 12:44
Show Gist options
  • Save SergLam/d41ba6bcd0d59a405e3de89e612452ec to your computer and use it in GitHub Desktop.
Save SergLam/d41ba6bcd0d59a405e3de89e612452ec to your computer and use it in GitHub Desktop.
Round image view with gradient border color
import UIKit
extension UIImageView {
func addCircleGradiendBorder(_ width: CGFloat) {
let gradient = CAGradientLayer()
gradient.frame = CGRect(origin: CGPoint.zero, size: bounds.size)
let colors: [CGColor] = [UIColor.supSoftGreenThree.cgColor, UIColor.supSoftGreenTwo.cgColor,
UIColor.supSoftGreen.cgColor, UIColor.supTea.cgColor,
UIColor.supAquaMarineTwo.cgColor, UIColor.supAquaMarineThree.cgColor,
UIColor.supAquaMarineFour.cgColor, UIColor.supAquaMarineFive.cgColor,
UIColor.supAzureThree.cgColor, UIColor.supAzureFour.cgColor, UIColor.supAzure.cgColor]
gradient.colors = colors
gradient.startPoint = CGPoint(x: 1, y: 0.5)
gradient.endPoint = CGPoint(x: 0, y: 0.5)
let cornerRadius = frame.size.width / 2
layer.cornerRadius = cornerRadius
clipsToBounds = true
let shape = CAShapeLayer()
let path = UIBezierPath(ovalIn: bounds)
shape.lineWidth = width
shape.path = path.cgPath
shape.strokeColor = UIColor.black.cgColor
shape.fillColor = UIColor.clear.cgColor // clear
gradient.mask = shape
layer.insertSublayer(gradient, below: layer)
}
}
@mehdin13
Copy link

great.thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment