ytpm
ytpm

Reputation: 5150

How to flash/change a UIButton borderColor with animation

I have UIButton and I want to add a continuously flash/change borderColor animation to it. So it should start with no border color then after 1 sec change to green, then repeat.

How can I do that?

Upvotes: 0

Views: 1273

Answers (1)

truongky
truongky

Reputation: 1147

Hope this can help

    targetButton.layer.borderWidth = 8.0
    let color: CABasicAnimation = CABasicAnimation(keyPath: "borderColor")
    color.fromValue = UIColor.clearColor().CGColor
    color.toValue = UIColor.greenColor().CGColor
    color.duration = 0.5
    color.autoreverses = true
    self.targetButton.layer.borderColor = UIColor.clearColor().CGColor
    self.targetButton.layer.addAnimation(color, forKey: "")

sorry, I forgot to set button border width. you can try again.

Upvotes: 4

Related Questions