We all wish that our apps could run without latency and pauses, but the reality is loading screens are needed from time to time. Today’s advent tip is how to display an activity indicator in your app like the one seen below. It’s great for soothing the savage, impatient user.
It can actually be done with just a few lines of code. First, we create and position the UIActivityIndicatorView by doing the following. It needs to be added to a view, so be sure to replace “myView” with your own view.
UIActivityIndicatorView *activityView = [[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge] autorelease]; [myView addSubview: activityView]; activityView.center = CGPointMake(240,160);
So now the activity indicator is created and positioned but it isn’t visible yet. You can make it visible at any time by running the following one line:
Finally, once you’ve finished loading the copious amounts of awesomesauce that fuel your app, you can make the activity indicator go away by running the following solitary line of code: