简体   繁体   中英

How do I create an animated boarder around a UIView in Swift

I want a border around a UIView that can fade in-and-out. I've created a border that shows once an action is done, but it's static and doesn't look very appealing.

This is the kind of border that I'm looking for in this GIF: LINK

Help would be appreciated as I'm really trying to get this working.

Thanks,

let borderWidth:CABasicAnimation = CABasicAnimation(keyPath: "borderWidth")
borderWidth.fromValue = 1
borderWidth.toValue = 5
borderWidth.duration = 1
borderWidth.autoreverses = true
borderWidth.repeatDuration = 300
view.layer.borderWidth = 5
view.layer.borderColor = UIColor.red.cgColor
view.layer.add(borderWidth, forKey: "Width")
view.layer.borderWidth = 1.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM