If you ever need a progress indicator for your app (and I am sure you will need in 90% of the cases), then MDProgressHUD is the right library for you. The library supports both Objective-C and Swift programming languages, but I will focus this tutorial showing you how to do it in Swift.
What is MBProgressHUD?
MBProgressHUD is an iOS drop-in class that displays a translucent HUD with an indicator and/or labels while work is being done in a background thread. The HUD is meant as a replacement for the undocumented, private UIKit UIProgressHUD with some additional features.
For installation I would highly recommend using CocoaPods.
After the installation, import the library where you need it.
You are good to go!
How to use it?
There are multiple ways to use it. You can either use the default HUD with a single line of code or customize it per your needs.
#1. Default HUD Implementation
MBProgressHUD.showAdded(to: self.view, animated: true)
MBProgressHUD.hide(for: self.view, animated: true)
#2 Custom HUD Implementation
let hud = MBProgressHUD.showAdded(to: self.view, animated: true) hud.animationType = .zoom hud.contentColor = UIColor.red hud.mode = .indeterminate
It supports lots of customization options which you can play around with. One more example would be adding a progress indication
let hud = MBProgressHUD.showAdded(to: self.view, animated: true) hud.animationType = .zoom hud.contentColor = UIColor.red hud.mode = .determinateHorizontalBar hud.progress = 0.3 /* 0.0 - 1.0 */
I hope that this tutorial helped you in deciding which progress indicator you will use in your future iOS apps. If you found this tutorial helpful, don’t forget to share. 🙂