其他分享
首页 > 其他分享> > MBProgressHUD Swift 简易封装

MBProgressHUD Swift 简易封装

作者:互联网

 

 

 1       /**
 2      可带文字的菊花
 3      */
 4     class func showWait(_ Text: String?){
 5         let  showView = viewToShow()
 6         let hud = MBProgressHUD.showAdded(to: showView, animated: true)
 7         hud.label.text = Text
 8         hud.removeFromSuperViewOnHide = true
 9     }
10     
11     /**
12      闪现1.5秒钟的文字
13      */
14     class func showMoment(_ Text: String){
15         let  showView = viewToShow()
16         let hud = MBProgressHUD.showAdded(to: showView, animated: true)
17         hud.mode = .text
18         hud.label.text = Text
19         hud.removeFromSuperViewOnHide = true
20         //HUD窗口显示1秒后自动隐藏
21         hud.hide(animated: true, afterDelay: 1)
22     }
23     
24     /**
25      可带文字的进度圈
26      */
27     class func showProgressRound(_ Text: String?, _ Progress: Float){
28         let  showView = viewToShow()
29         let hud = MBProgressHUD.showAdded(to: showView, animated: true)
30         hud.mode = .determinate
31         hud.label.text = Text
32         hud.removeFromSuperViewOnHide = true
33         hud.progress = Progress
34         
35         if hud.progress == 1 {
36             close()
37         }
38     }
39     
40     /**
41      可带文字的进度条
42      */
43     class func showProgressStrips(_ Text: String?, _ Progress: Float){
44         let  showView = viewToShow()
45         let hud = MBProgressHUD.showAdded(to: showView, animated: true)
46         hud.mode = .determinateHorizontalBar
47         hud.label.text = Text
48         hud.removeFromSuperViewOnHide = true
49         hud.progress = Progress
50         
51         if hud.progress == 1 {
52             close()
53         }
54     }
55     
56     /**
57      关闭HUD
58      */
59     class func close() {
60         let  showView = viewToShow()
61         MBProgressHUD.hide(for: showView, animated: true)
62     }
63     
64     
65     ///获取用于显示提示框的view
66     class func viewToShow() -> UIView {
67         var window = UIApplication.shared.keyWindow
68         if window?.windowLevel != UIWindowLevelNormal {
69             let windowArray = UIApplication.shared.windows
70             for tempWin in windowArray {
71                 if tempWin.windowLevel == UIWindowLevelNormal {
72                     window = tempWin;
73                     break
74                 }
75             }
76         }
77         return window!
78     }

 

标签:hud,封装,true,MBProgressHUD,let,Text,showView,Swift
来源: https://www.cnblogs.com/-yun/p/14548595.html