143 lines
5.2 KiB
Swift
143 lines
5.2 KiB
Swift
//
|
||
// MPHUD.swift
|
||
// MusicPlayer
|
||
//
|
||
// Created by Mr.Zhou on 2024/4/11.
|
||
//
|
||
|
||
import UIKit
|
||
import SVProgressHUD
|
||
///二次封装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(.init(hex: "#80F988", alpha: 0.1))
|
||
SVProgressHUD.setForegroundColor(.init(hex: "#80F988"))
|
||
SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: 0))
|
||
if MP_AdMobManager.shared.getInterstitialSwitch() {
|
||
//当前正在展示插页
|
||
|
||
}else {
|
||
//没有展示插页
|
||
SVProgressHUD.show()
|
||
}
|
||
}
|
||
///特制下载文本HUD
|
||
static func downloadText(_ text:String, delay:TimeInterval, completion:(() -> Void)?) {
|
||
SVProgressHUD.setDefaultStyle(.light)
|
||
SVProgressHUD.setDefaultMaskType(.none)
|
||
SVProgressHUD.setBackgroundColor(.init(hex: "#80F988", alpha: 0.1))
|
||
SVProgressHUD.setForegroundColor(.init(hex: "#80F988"))
|
||
if MP_AdMobManager.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(.init(hex: "#151718", alpha: 0.4))
|
||
SVProgressHUD.setForegroundColor(.white)
|
||
SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: 0))
|
||
if MP_AdMobManager.shared.getInterstitialSwitch() {
|
||
//当前正在展示插页
|
||
guard let completion = completion else{
|
||
return
|
||
}
|
||
completion()
|
||
}else {
|
||
switch status {
|
||
case .success:
|
||
SVProgressHUD.showSuccess(withStatus: text)
|
||
SVProgressHUD.setMinimumSize(CGSize(width: 100 * width, height: 80 * width))
|
||
SVProgressHUD.show(UIImage(), status: text)
|
||
case .error:
|
||
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()
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|