The Activity Indicator can be used to show the user that a task is in progress. In this tutorial we will start and stop the Activity Indicator and display on the status bar.
Open Xcode and create a new Single View Application. For product name, use ActivityIndicatorStatusBarDemo and then fill out the Organization Name, Company Identifier and Class Prefix fields with your customary values. Make sure only iPhone is selected in Devices, and that the Use Storyboards checkbox is deselected and Use Automatic Reference Counting checkbox is selected.
First, let's create our User Interface. Open ViewController.xib and drag 2 buttons to the main view and name the buttons start and stop. The view should look like this.
Select the Assistant Editor. Open The ViewController.xib and ViewController.m files. Ctrl+Drag from the buttons to the interface section and create the following IBAction method declarations.
@interface ViewController ()
Implement the startActivity and stopActivity methods
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
This will display and hide the activity indicator from the status bar. Build and Run, and click the start button to display the activity indicator.
You can download the source code of the ActivityIndicatorStatusBarDemo at the ioscreator repository on github.