MBProgressHUD+JChat.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // MBProgressHUD+JChat.swift
  3. // JChat
  4. //
  5. // Created by deng on 2017/3/16.
  6. // Copyright © 2017年 HXHG. All rights reserved.
  7. //
  8. import UIKit
  9. import MBProgressHUD
  10. class MBProgressHUD_JChat: MBProgressHUD {
  11. public static func showMessage(message: String, toView: UIView?) {
  12. DispatchQueue.main.async {
  13. var currentView = toView
  14. if toView == nil {
  15. currentView = UIApplication.shared.keyWindow
  16. }
  17. let hud = MBProgressHUD.showAdded(to: currentView!, animated: true)
  18. hud.label.text = message
  19. hud.label.textColor = UIColor(white: 1, alpha: 0.7)
  20. hud.bezelView.color = .black
  21. hud.activityIndicatorColor = UIColor(netHex: 0x9B9B9B)
  22. hud.removeFromSuperViewOnHide = true
  23. }
  24. }
  25. public static func show(text: String, view: UIView?, _ time: TimeInterval = 1.5) {
  26. DispatchQueue.main.async {
  27. var currentView = view
  28. if view == nil {
  29. currentView = UIApplication.shared.keyWindow
  30. }
  31. let hud = MBProgressHUD.showAdded(to: currentView!, animated: true)
  32. hud.label.text = text
  33. hud.bezelView.color = .black
  34. hud.mode = .customView
  35. hud.removeFromSuperViewOnHide = true
  36. hud.label.textColor = UIColor(white: 1, alpha: 0.7)
  37. hud.hide(animated: true, afterDelay: time)
  38. }
  39. }
  40. public static func hide(forView: UIView?, animated: Bool) {
  41. DispatchQueue.main.async {
  42. var currentView = forView
  43. if currentView == nil {
  44. currentView = UIApplication.shared.keyWindow
  45. }
  46. MBProgressHUD.hide(for: currentView!, animated: animated)
  47. }
  48. }
  49. }