Hide activity indicator

ぐ巨炮叔叔 提交于 2019-12-01 17:29:21

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.

You can add

self.indicator.hidden = YES;

to your UIViewController's viewDidLoad method or select Hidden checkmark in Storyboard.

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()

Yes, you can select Hidden property in the Storyboard, and change it in your button action method when you tap it. But you can just select Hides when Stopped and your activity will be hidden if not animating and show up otherwise.

if you are using swift then you can do it when you set the outlet of your indicator, like-

@IBOutlet weak var indicator:UIActivityIndicatorView!{
     didSet{
          indicator.hidesWhenStopped = true
     }
}

Basically what it meant is, set my activity indicator outlet's hidesWhenStopped property to true when it is established.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!