Posts with the tag xcode:

How to animate the change of background color of a view on iOS ?

Step by step guide to create background color changing with beautiful animation open Main.storyboard add a button as shown below add one @IBAction for touchUpInside of ‘Change Background’ button. Name the function as changeBackgroundClicked. use animate function of UIView to animate the change of background color. It provides us the duration and optional completion as parameters. In changeBackgroundClicked we will change the background color of the view from red to blue and vice versa. Here is the code. @IBAction func changeBackgroundClicked(_ sender: Any) { if self.view.backgroundColor == { UIView.animate(withDuration: 2) { self.view.backgroundColor = UIColor.