Activity Indicator iOS Tutorial

An Activity Indicator is a spinning wheel that indicates a task is being processed. if an action takes an unknown amount of time to process you should display an activity indicator to let the user know your app is not frozen. In this tutorial we will start and stop the spinning animation of the activity indicator. This tutorial is made with Xcode 10 and built for iOS 12.

Open Xcode and create a new Single View App.

For product name, use IOS12ActivityIndicatorTutorial and then fill out the Organization Name and Organization Identifier with your customary values. Enter Swift as Language and choose Next.

Go to the Storyboard and drag two buttons to the main view. Set the title of the buttons to "Start" and "Stop". Also Drag an Activty Indicator View to the main view and position it below the other two buttons,

The Storyboard should look like this.

Select the Assistant Editor and make sure the ViewController.swift is visible. Ctrl and drag from the Start Button to the ViewController class and create the following Action.

Ctrl and drag from the Stop Button to the ViewController class and create the following Action.

Ctrl and drag from the Activity Indicator View to the ViewController class and create the following Outlet.

Implement the startSpinning method

@IBAction func startSpinning(_ sender: Any) {
    activityView.startAnimating()
}

Implement the stopSpinning method

@IBAction func stopSpinning(_ sender: Any) {
    activityView.stopAnimating()
}

Build and Run the project. Press the buttons to start and stop the Activity Indicator.

You can download the source code of the IOS12ActivityIndicatorTutorial at the ioscreator repository on Github.