- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to use MBProgressHUD with swift?
To use MBProgressHUD in swift we first need to create a podfile if it does not exist already.
Go to terminal and change directory to your project directory then initialize pod and later install MBProgressHUD.
cd /projectDirectory pod init open podfile
Then in the podfile add the following line and go back to the terminal and run the below command in the same directory.
pod 'MBProgressHUD', '~> 1.1.0' pod install
Once you run these commands MBProgressHUD will be installed to your project, now you can import this library in ViewController where ever you want to use, or you may create an extension of UIView controller and use this method.
Let’s see this with two different methods, both of which will produce the same result.
1. Adding in ViewDidLoad
let Indicator = MBProgressHUD.showAdded(to: self.view, animated: true) Indicator.label.text = "Indicator" Indicator.isUserInteractionEnabled = false Indicator.detailsLabel.text = "fetching details" Indicator.show(animated: true)
Similarly, you may use the following to hide indicator from the view.
MBProgressHUD.hide(for: self.view, animated: true)
Let’s have a look at the second way of doing the same.
2. Creating an extension to make it globally accessible.
extension UIViewController { func showIndicator(withTitle title: String, and Description:String) { let Indicator = MBProgressHUD.showAdded(to: self.view, animated: true) Indicator.label.text = title Indicator.isUserInteractionEnabled = false Indicator.detailsLabel.text = Description Indicator.show(animated: true) } func hideIndicator() { MBProgressHUD.hide(for: self.view, animated: true) } }
When we run any of these on our device, we get the following result.
- Related Articles
- How to use UICollectionView in Swift?
- How to use the front camera in Swift?
- How to create and use Global Variable in swift
- Where and how to use static variable in swift?
- How to use Swift to detect when AVPlayer video ends playing?
- How to use Swift to run in background to provide current location?
- How to determine device type (iPhone, iPod Touch) with Swift?
- How to use try-with-resources with JDBC?
- How to use Selenium with Python?
- How to display an image with rounded corners on iOS App using Swift?
- How to resize an UIImageView using Swift?
- How to add shadow on text swift?
- How to detect shake gesture using Swift?
- How to make iPhone vibrate using Swift?
- How to use Constraint Layout with recyclerview?
