How to use MBProgressHUD with swift

后端 未结 10 1623
北海茫月
北海茫月 2020-12-08 02:23

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          


        
相关标签:
10条回答
  • 2020-12-08 02:54

    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
        }
    }
    
    0 讨论(0)
  • 2020-12-08 02:56

    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)
    
    0 讨论(0)
  • 2020-12-08 02:57

    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)
    }
    
    0 讨论(0)
  • 2020-12-08 02:59

    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/

    0 讨论(0)
提交回复
热议问题