Music_Player3/MusicPlayer/MP/Common/Tool(工具封装)/MP_HUD.swift
2024-05-31 17:05:17 +08:00

96 lines
3.3 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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 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))
SVProgressHUD.show()
}
///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(.init(hex: "#80F988", alpha: 0.1))
SVProgressHUD.setForegroundColor(.init(hex: "#80F988"))
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()
}
}
}