Music_Player3/MusicPlayer/MP/Common/Tool(工具封装)/MP_HUD.swift
2024-05-11 09:48:37 +08:00

85 lines
2.8 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
}
///HUD
static func text(_ text:String?,delay:TimeInterval,completion:(() -> Void)?){
showWithStatus(hudStatus: .onlyText, 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(.white)
SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: 0))
switch status {
case .success:
SVProgressHUD.showSuccess(withStatus: text)
SVProgressHUD.setMinimumSize(CGSize(width: 100 * width, height: 80 * width))
case .error:
SVProgressHUD.showError(withStatus: text)
case .onlyText:
SVProgressHUD.setOffsetFromCenter(.init(horizontal: 0, vertical: (screen_Height / 2) - 85 * width))
SVProgressHUD.setMinimumSize(CGSize(width: 100 * width, height: 40 * width))
SVProgressHUD.show(UIImage(), status: text)
case .loading:
SVProgressHUD.setBackgroundColor(.white)
SVProgressHUD.show()
default:
SVProgressHUD.show(withStatus: text)
}
SVProgressHUD.dismiss(withDelay: delay) {
guard let completion = completion else{
return
}
completion()
}
}
}