Hide activity indicator

Swift 3 Xcode 8.3.2

First hide your activityIndicator in viewDidLoad() method and set hidesWhenStopped property to true.

override func viewDidLoad(){
     super.viewDidLoad()
     self.activityIndicator.isHidden = true
     self.activityIndicator.hidesWhenStopped = true
}

Later when you want to show activityIndicator :

self.activityIndicator.isHidden = false
self.activityIndicator.startAnimating()

And when you want to stop it use :

self.activityIndicator.stopAnimating()

Select the Activity Indicator in Storyboard, then select property "Hides when stopped". This way you don't have to hide it, just start or stop the animation, and the Activity Indicator will show and hide automatically. Of course, you still have to add the code to start and stop the animation to buttons.

storyboard