Animate UIView background color swift
Just put the animation in getRandomColor
.
func getRandomColor() { let red = CGFloat((arc4random() % 256)) / 255.0 let green = CGFloat((arc4random() % 256)) / 255.0 let blue = CGFloat((arc4random() % 256)) / 255.0 let alpha = CGFloat(1.0) UIView.animate(withDuration: 1.0, delay: 0.0, options:[.repeat, .autoreverse], animations: { self.view.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: alpha) }, completion:nil)}