How to create an animated progress indicator in Swift

Oscar de la Hera Gomez
Two flowers that represent Swift and Xcode side by side with the text "Animated Progress Indicator" beneath them.

A step by step on creating a custom progress indicator in Swift and Xcode.

We recommend that you clone our Open Source Swift Starter Project, checking out the main branch and carrying out the steps below. The changes can be found on the tutorial/custom/progress-indicator branch.

git clone git@github.com:delasign/swift-starter-project.git

Step One: Create the Progress Indicator

A screenshot of Xcode showing all the files that we created for the progress indicator as part of this step.

The following step involves creating the files and code for the Progress Indicator.

We recommend that these files fall under the UI/Components folder.

A | Declaration

A screenshot of XCode showing the ProgressIndicator.swift file. Code available below.

Create a file called ProgressIndicator.swift and paste in the code below.

B | UI

A screenshot of XCode showing the ProgressIndicator+UI.swift file. Code available below.

Create a file called ProgressIndicator+UI.swift and paste in the code below.

C | Notifications

A screenshot of XCode showing the ProgressIndicator+Notifications.swift file. Code available below.

Create a file called ProgressIndicator+Notifications.swift and paste in the code below.

This code is responsible for stopping animation when the app goes into the background and starting it when it comes back to the foreground.

If you do not stop it it will cause the app to severely hang when coming from the Lock Screen or background.

This code should be modified depending on how you use the progress indicator.

D | Animations

A screenshot of XCode showing the ProgressIndicator+Animations.swift file. Code available below.

Create a file called ProgressIndicator+Animations.swift and paste in the code below.

E | Update

A screenshot of XCode showing the ProgressIndicator+Update.swift file. Code available below.

Create a file called ProgressIndicator+Update.swift and paste in the code below.

Step Two: Add to the UI

A screenshot of Xcode showing the files that are modified as part of this step.

The following step involves adding the Progress Indicator to the UI.

Please note that we have removed the label functionality that comes with our main branch, but have not documented how to do this as part of this tutorial.

A | Declare

A screenshot of Xcode highlighting how we have declared a progress indicator.

In CustomUIView.swift, or your UIView/UIViewController, add the Progress Indicator.

B | Add to UI

A screenshot of Xcode showing the functionality that we used to add the Progress Indicator to the UI.

In the ViewController+UI.swift file, add the progress indicator declared in part A to the app.

Step Three: Test

A screenshot of an iPhone showing a progress indicator.

Run the code on a device and confirm that the progress indicator works as expected.

Looking to learn more about things you can do with Swift and XCode ?

Search our blog to find educational content on learning how to use Swift and XCode.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details