#JHProgressHUD
JHProgressHUD is an iOS class written in Swift to display 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 private UIKit UIProgressHUD.
Add the JHProgressHUD.swift
file to your project.
- Download the latest code version or add the repository as a git submodule to your git-tracked project.
- Open your project in Xcode, then drag and drop
JHProgressHUD.swift
onto your project (use the "Product Navigator view"). Make sure to select Copy items when asked if you extracted the code archive outside of your project.
The JHProgressHUD
is a singleton class and has only a single instance throughout the project. That is you see the same HUD added to multiple views. As a result, HUD duplication doesn't happen. You can use the following code to access the instance of JHProgressHUD
anywhere inside the project.
JHProgressHUD.sharedHUD
To show the HUD added to a view, with a title and footer text, use the following code:
JHProgressHUD.sharedHUD.showInView(self.view, withHeader: "Loading", andFooter: "Please Wait")
To show the HUD added to a window, with a title and footer text, use the following code:
JHProgressHUD.sharedHUD.showInWindow(aWindow, withHeader: "Loading", andFooter: "Please Wait")
To show the HUD without any header and footer text added to a view:
JHProgressHUD.sharedHUD.showInView(self.view)
To show the HUD without any header and footer text added to a window:
JHProgressHUD.sharedHUD.showInWindow(aWindow)
To hide the loader, you can call the following function from any class. The HUD will be removed from any view it is shown in:
JHProgressHUD.sharedHUD.hide()
You can also change the colors of different elements of the HUD using the following four properties:
JHProgressHUD.sharedHUD.headerColor = UIColor.redColor() // Changes the color of the title text
JHProgressHUD.sharedHUD.footerColor = UIColor.greenColor() // Changes the color of the footer text
JHProgressHUD.sharedHUD.backGroundColor = UIColor.blueColor() // Changes the color of the translucent background
JHProgressHUD.sharedHUD.loaderColor = UIColor.yellowColor() // Changes the color of the loading indicator
The HUD might not show if you try to display the loader in a ViewController
's viewDidLoad()
method, since adding subviews maynot always work in the viewDidLoad()
. It is prefered to show the HUD at least only after the viewWillAppear()
is called. The HUD blocks the user interaction in the underlying view or window once it is shown, till it is hidden.
This code is distributed under the terms and conditions of the MIT license.