For some reason this isn\'t working for me:
let color = CABasicAnimation(keyPath: \"borderColor\")
color.fromValue = sender.layer.borderColor;
color.toValue
Swift 4 UIView
extension:
extension UIView {
func animateBorderColor(toColor: UIColor, duration: Double) {
let animation:CABasicAnimation = CABasicAnimation(keyPath: "borderColor")
animation.fromValue = layer.borderColor
animation.toValue = toColor.cgColor
animation.duration = duration
layer.add(animation, forKey: "borderColor")
layer.borderColor = toColor.cgColor
}
}
And then just use it by writing:
myView.animateBorderColor(toColor: .red, duration: 0.5)