// // MPHUD.swift // MusicPlayer // // Created by Mr.Zhou on 2024/4/11. // import UIKit import SVProgressHUD let HUDBackColor:UIColor = .init(hex: "#808080", alpha: 0.7) let HUDTextColor:UIColor = .white ///二次封装hud class MP_HUD: NSObject { //HUD输出状态 enum status { ///成功 case success ///失败 case error ///网络文字 case onlyText ///过程 case progress ///加载数据 case loading ///文本 case text } ///直接展示HUD,纯等待 static func loading(){ SVProgressHUD.setDefaultStyle(.light) SVProgressHUD.setDefaultMaskType(.clear) SVProgressHUD.setBackgroundColor(HUDBackColor) SVProgressHUD.setForegroundColor(HUDTextColor) SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: 0)) if MP_ADSimpleManager.shared.getInterstitialSwitch() { //当前正在展示插页 }else { //没有展示插页 SVProgressHUD.show() } } ///特制下载文本HUD static func downloadText(_ text:String, delay:TimeInterval, completion:(() -> Void)?) { SVProgressHUD.setDefaultStyle(.light) SVProgressHUD.setDefaultMaskType(.none) SVProgressHUD.setBackgroundColor(HUDBackColor) SVProgressHUD.setForegroundColor(HUDTextColor) SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: 0)) if MP_ADSimpleManager.shared.getInterstitialSwitch() { //当前正在展示插页 guard let completion = completion else{ return } completion() }else { //没有展示插页 SVProgressHUD.showInfo(withStatus: text) SVProgressHUD.dismiss(withDelay: delay) { guard let completion = completion else{ return } completion() } } } ///文本HUD static func text(_ text:String?,delay:TimeInterval,completion:(() -> Void)?){ showWithStatus(hudStatus: .onlyText, text: text, delay: delay, completion: completion) } static func onlytext(_ text:String?,delay:TimeInterval,completion:(() -> Void)?){ showWithStatus(hudStatus: .text, text: text, delay: delay, completion: completion) } ///等待HUD static func progress(_ text:String?,delay:TimeInterval,completion:(() -> Void)?){ showWithStatus(hudStatus: .progress, text: text, delay: delay, completion: completion) } ///数据HUD static func loading(_ delay:TimeInterval,completion:(() -> Void)?){ showWithStatus(hudStatus: .loading, text: nil, delay: delay, completion: completion) } ///成功HUD static func success(_ text:String?,delay:TimeInterval,completion:(() -> Void)?){ showWithStatus(hudStatus: .success, text: text, delay: delay, completion: completion) } ///错误HUD static func error(_ text:String?,delay:TimeInterval,completion:(() -> Void)?){ showWithStatus(hudStatus: .error, text: text, delay: delay, completion: completion) } //立刻隐藏当前HUD static func hideNow() { SVProgressHUD.dismiss() } /// 展示HUD /// - Parameters: /// - status: HUD状态 /// - text: 显示文本 /// - delay: 显示时常 static func showWithStatus(hudStatus status: status, text: String?, delay: TimeInterval ,completion:(() -> Void)?) { SVProgressHUD.setDefaultStyle(.light) SVProgressHUD.setDefaultMaskType(.clear) SVProgressHUD.setBackgroundColor(HUDBackColor) SVProgressHUD.setForegroundColor(HUDTextColor) SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: 0)) if MP_ADSimpleManager.shared.getInterstitialSwitch() { //当前正在展示插页 guard let completion = completion else{ return } completion() }else { switch status { case .success: SVProgressHUD.setBackgroundColor(HUDBackColor) SVProgressHUD.showSuccess(withStatus: text) SVProgressHUD.setMinimumSize(CGSize(width: 100 * width, height: 80 * width)) SVProgressHUD.show(UIImage(), status: text) case .error: SVProgressHUD.setBackgroundColor(HUDBackColor) SVProgressHUD.showError(withStatus: text) case .onlyText: SVProgressHUD.setMinimumSize(CGSize(width: 100 * width, height: 40 * width)) SVProgressHUD.show(UIImage(named: "NoNetReache'log")!, status: text) case .loading: SVProgressHUD.setBackgroundColor(.white) SVProgressHUD.show() case .text: SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: (screen_Height / 2) - 85 * width)) SVProgressHUD.show(UIImage(), status: text) default: // SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: (screen_Height / 2) - 85 * width)) SVProgressHUD.show(withStatus: text) } SVProgressHUD.dismiss(withDelay: delay) { guard let completion = completion else{ return } completion() } } } }