Created
April 17, 2019 12:44
-
-
Save SergLam/d41ba6bcd0d59a405e3de89e612452ec to your computer and use it in GitHub Desktop.
Round image view with gradient border color
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
great.thanks