Hide activity indicator
Asked Answered
N

5

11

On my main storyboard I created an Activity Indicator.

I want to hide my activity indicator until the button has been pressed. Is there a way I can do that?

When I press the button the activity indicator starts animating.

self.indicator.hidden = NO;
[self.indicator startAnimating];
[self performSelector:@selector(showData) withObject:nil afterDelay:2.0f];

Can I hide the activity indicator until the button has been pressed, and then show this activity indicator?

Nannette answered 4/3, 2015 at 21:47 Comment(1)
If you want, you can choose any of the answers as the right one.Dynel
P
19

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

Particle answered 4/3, 2015 at 22:3 Comment(0)
A
5

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()
Ashaashamed answered 28/9, 2017 at 7:46 Comment(0)
E
0

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.

Exhaustive answered 4/3, 2015 at 21:58 Comment(0)
J
0

You can add

self.indicator.hidden = YES;

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

Jea answered 4/3, 2015 at 22:0 Comment(0)
W
0

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.

Whoop answered 11/5, 2019 at 8:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.