CocoaPods trunk is moving to be read-only. Read more on the blog, there are 17 months to go.
TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Nov 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✗ |
Maintained by ming.
Swift version of 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.
To run the example project, clone the repo, and run pod install
from the Example directory first.
XProgressHUD
works on iOS 8+ and swift 4.0.
CocoaPods is the recommended way to add MBProgressHUD to your project.
pod 'XProgressHUD'
pod install
.import XProgressHUD
.Alternatively you can directly add the XProgressHUD.swift
to your project.
The main guideline you need to follow when dealing with MBProgressHUD while running long-running tasks is keeping the main thread work-free, so the UI can be updated promptly. The recommended way of using MBProgressHUD is therefore to set it up on the main thread and then spinning the task, that you want to perform, off onto a new thread.
ProgressHUD.showHUD(forView: self.view, animated: true)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 10) {
ProgressHUD.hideHUD(forView: self.view, animated: true)
}
If you need to configure the HUD you can do this by using the XProgressHUD reference that showHUDAddedTo:animated: returns.
let hub = ProgressHUD.showHUD(forView: self.view, animated: true)
hub?.label.text = "加载中"
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 10) {
ProgressHUD.hideHUD(forView: self.view, animated: true)
}
You can also use a NSProgress
object and MBProgressHUD will update itself when there is progress reported through that object.
let hub = ProgressHUD.showHUD(forView: self.scrollView, animated: true)
hub?.mode = .determinate
hub?.label.text = "加载中..."
hub?.detailsLabel.text = "(1/2)"
hud?.progressObject = progress;
You should be aware that any HUD updates issued inside the above block won't be displayed until the block completes.
ming, [email protected]
XProgressHUD is available under the MIT license. See the LICENSE file for more info.