SwiftProgressHUD 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.
| 1 | 2 | 3 | 4 |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| 1 | 2 | 3 | 4 |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
SwiftProgressHUD works on iOS 8+ and requires ARC to build. It depends on the following Apple frameworks, which should already be included with most Xcode templates:
- Swift 3.0+
- Foundation.framework
- UIKit.framework
- CoreGraphics.framework
You will need the latest developer tools in order to build SwiftProgressHUD. Old Xcode versions might work, but compatibility will not be explicitly maintained.
CocoaPods is the recommended way to add SwiftProgressHUD to your project.
- Add a pod entry for
SwiftProgressHUDto your Podfile
pod 'SwiftProgressHUD'- Install the pod(s) by running
pod install- Include
SwiftProgressHUDwherever you need it with
import SwiftProgressHUD- Add SwiftProgressHUD to your Cartfile.
github "stackhou/SwiftProgressHUD"- Run
carthage update- Follow the rest of the standard Carthage installation instructions to add SwiftProgressHUD to your project.
在需要等待的时候, 可以使用 showWait, 代码及效果如下:
/// 设置蒙版背景颜色, 默认是clear
// SwiftProgressHUD.hudBackgroundColor = UIColor.black.withAlphaComponent(0.2)
/// 开始loading...
SwiftProgressHUD.showWait()
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
SwiftProgressHUD.hideAllHUD()
}加载成功时, 提示可以使用 showSuccess, 代码及效果如下:
SwiftProgressHUD.showSuccess("加载成功")
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
SwiftProgressHUD.hideAllHUD()
}加载失败时, 提示可以使用 showFail, 代码及效果如下:
SwiftProgressHUD.showFail("加载失败")
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
SwiftProgressHUD.hideAllHUD()
}友情提示信息, 可以使用 showInfo, 代码及效果如下:
SwiftProgressHUD.showInfo("请稍后")
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
SwiftProgressHUD.hideAllHUD()
}错误Toast提示信息, 可以使用 showOnlyText, 代码及效果如下:
SwiftProgressHUD.showOnlyText("请输入合法的手机号")
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
SwiftProgressHUD.hideAllHUD()
}状态栏提示信息, 可以使用 showOnStatusBar, 代码及效果如下:
SwiftProgressHUD.showOnStatusBar("你有一条新消息", autoClear: true, autoClearTime: 1, textColor: UIColor.orange, backgroundColor: UIColor.lightGray)
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
SwiftProgressHUD.hideAllHUD()
}加载动画提示, 可以使用 showAnimationImages, 代码及效果如下:
let animationDuration = 70 // 动画时间 单位毫秒Int
var loadingImages = [UIImage]()
for index in 0...16 {
let loadImageName = String(format: "new_brand_progress%02d", index)
if let loadImage = UIImage(named: loadImageName) {
loadingImages.append(loadImage)
}
}
SwiftProgressHUD.showAnimationImages(loadingImages, timeMilliseconds: animationDuration, backgroundColor: backgroundColor, scale: scale)
/// 模拟 1s后 加载完成
DispatchQueue.main.asyncAfter(deadline: .now() + 4) {
SwiftProgressHUD.hideAllHUD()
}| 1 | 2 | 3 |
|---|---|---|
![]() |
![]() |
![]() |
This code is distributed under the terms and conditions of the MIT license.
A brief summary of each MBProgressHUD release can be found in the CHANGELOG.









