Use of MBProgressHUD Globally + make it singleton

后端 未结 9 1213
时光说笑
时光说笑 2020-12-23 02:06

In my Project, each of the user interaction events make a network call (Which is TCP, not HTTP). I need Activity Indicator to be global to show from a rando

9条回答
  •  悲哀的现实
    2020-12-23 02:32

    I found @Matej Bukovinski 's answer very helpful, since I just started using Swift and my purpose using his methods was to set a global font for the MBProgressHUD, I have converted the code to swift and am willing to share the code below:

    class func showGlobalProgressHUDWithTitle(title: String) -> MBProgressHUD{
        let window:UIWindow = UIApplication.sharedApplication().windows.last as! UIWindow
        let hud = MBProgressHUD.showHUDAddedTo(window, animated: true)
        hud.labelText = title
        hud.labelFont = UIFont(name: FONT_NAME, size: 15.0)
        return hud
    }
    
    class func dismissGlobalHUD() -> Void{
        let window:UIWindow = UIApplication.sharedApplication().windows.last as! UIWindow
        MBProgressHUD.hideAllHUDsForView(window, animated: true)
    }
    

    The above code is put into a global file where I keep all my global helpers and constants.

提交回复
热议问题