here is my code , but it showing the progress . is there any error in this code? please give some idea to fix this, or give some link related to this.
class
I solved it like this:
import UIKit
class Loader: NSObject {
class func show(message:String = "Processing...", delegate: UIViewController) {
var load : MBProgressHUD = MBProgressHUD()
load = MBProgressHUD.showHUDAddedTo(delegate.view, animated: true)
load.mode = MBProgressHUDMode.Indeterminate
if message.length > 0 {
load.labelText = message;
}
UIApplication.sharedApplication().networkActivityIndicatorVisible = true
}
class func hide(delegate:UIViewController) {
MBProgressHUD.hideHUDForView(delegate.view, animated: true)
UIApplication.sharedApplication().networkActivityIndicatorVisible = false
}
}
Added to @EricDXS's answer,
The Swift 3 version is here
To show:
let loadingNotification = MBProgressHUD.showAdded(to: self.view, animated: true)
loadingNotification.mode = MBProgressHUDMode.indeterminate
loadingNotification.label.text = "Loading"
To dismiss:
loadingNotification.hide(animated: true)
step 1 : Download "MBProgressHUD.h" and "MBProgressHUD.m" file and Add both file into your project. it will ask you to Bridging for Objective C files. if you already done bridging then it won't ask.
step 2 : In Bridging File import MBProgressHUD "import MBProgressHUD.h"
step 3 : use below code to show progress hud or hide hud.
for Show
DispatchQueue.main.async {
MBProgressHUD.showAdded(to: self.view, animated: true)
}
for hide
DispatchQueue.main.async {
MBProgressHUD.hide(for: self.view, animated: true)
}
Use the below code to render MBProgressHUD and after some action completed hide it as described.
let spinnerActivity = MBProgressHUD.showHUDAddedTo(self.view, animated: true);
spinnerActivity.label.text = "Loading";
spinnerActivity.detailsLabel.text = "Please Wait!!";
spinnerActivity.userInteractionEnabled = false;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0))
{
// Add some background task like image download, wesite loading.
dispatch_async(dispatch_get_main_queue())
{
spinnerActivity.hideAnimated(true);
}
}
For more information follow this tutorial: http://sourcefreeze.com/mbprogresshud-example-swift/