KRProgressHUD
is a beautiful and easy-to-use progress HUD for your iOS written by Swift.
KRActivityIndicatorView is used for loading view.
- Round indicator
- Indicator color can be customized
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+
To run the example project, clone the repo, and open KRProgressHUDDemo.xcodeproj
from the DEMO directory.
or appetize.io
KRProgressHUD is available through CocoaPods and Carthage. To install it, simply add the following line to your Podfile or Cartfile:
# CocoaPods
pod "KRProgressHUD"
# Carthage
github "Krimpedance/KRProgressHUD"
(see sample Xcode project in /Demo)
Only use it if you absolutely need to perform a task before taking the user forward.
If you want to use it with other cases (ex. pull to refresh), I suggest using KRActivityIndicatorView.
KRProgressHUD
is created as a singleton.
At first, import KRProgressHUD
in your swift file.
Show simple HUD :
KRProgressHUD.show()
DispatchQueue.main.asyncAfter(deadline: .now()+1) {
KRProgressHUD.dismiss()
}
class func show(withMessage message:String? = nil, completion: CompleteHandler? = nil)
// Example
KRProgressHUD.show()
KRProgressHUD.show(withMessage: "Loading...")
KRProgressHUD.show(withMessage: "Loading...") {
print("Complete handler")
}
Show on ViewController
If you want to show HUD on a view controller, set at showOn()
.
(This is applied only once.)
KRProgressHUD.showOn(viewController).show()
Show a confirmation glyph before getting dismissed a little bit later. (The display time is 1 sec in default. You can change the timing.)
class func showSuccess()
class func showInfo()
class func showWarning()
class func showError()
class func showImage() // This can set custom image. (Max size is 50x50)
Show the HUD (only message)
public class func showMessage(_ message: String)
// Example
KRProgressHUD.showMessage("Completed! \n Let's start!")
The HUD can update message.
class func update(message: String)
// Example
KRProgressHUD.update(message: "20%")
The HUD can be dismissed using:
class func dismiss(_ completion: CompleteHandler? = nil)
KRProgressHUD.appearance()
can set default styles.
class KRProgressHUDAppearance {
/// Default style.
public var style = KRProgressHUDStyle.white
/// Default mask type.
public var maskType = KRProgressHUDMaskType.black
/// Default KRActivityIndicatorView style.
public var activityIndicatorStyle = KRActivityIndicatorViewStyle.gradationColor(head: .black, tail: .lightGray)
/// Default message label font.
public var font = UIFont.systemFont(ofSize: 13)
/// Default HUD center position.
public var viewCenterPosition = CGPoint(x: UIScreen.main.bounds.width/2, y: UIScreen.main.bounds.height/2)
/// Default time to show HUD.
public var deadlineTime = Double(1.0)
}
When you'd like to make styles reflected only in specific situation, use following methods.
@discardableResult public class func set(style: KRProgressHUDStyle) -> KRProgressHUD.Type
@discardableResult public class func set(maskType: KRProgressHUDMaskType) -> KRProgressHUD.Type
@discardableResult public class func set(activityIndicatorViewStyle style: KRActivityIndicatorViewStyle) -> KRProgressHUD.Type
@discardableResult public class func set(font: UIFont) -> KRProgressHUD.Type
@discardableResult public class func set(centerPosition point: CGPoint) -> KRProgressHUD.Type
@discardableResult public class func set(deadlineTime time: Double) -> KRProgressHUD.Type
// Example
KRProgressHUD
.set(style: .custom(background: .blue, text: .white, icon: nil))
.set(maskType: .white)
.show()
These set()
setting can be reset by
@discardableResult public class func resetStyles() -> KRProgressHUD.Type
I'm seeking bug reports and feature requests.
-
3.1.2 :
- Fixed bug of custom small image.
-
3.1.1 :
- Supported from iOS 8.0.
-
3.1.0 :
- Available at CocoaPods and Carthage with Xcode9 and Swift4.
-
3.0.0 :
- [ADD] Set styles with method chaining.
- [ADD] Show HUD on VC.
KRProgressHUD is available under the MIT license.
See the LICENSE file for more info.