123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- //
- // TSToastTool.swift
- // TSLiveWallpaper
- //
- // Created by 100Years on 2024/12/20.
- //
- import SVProgressHUD
- public let TSToastShared = TSToastTool.shared
- public let TSToastWindow = TSToastTool.getCurrentWindow()
- open class TSToastTool {
- public static let shared = TSToastTool()
-
- private init() {
- SVProgressHUD.swizzleMethods()
- // 如果您想要堆叠 HUD,您可以使用以下方法平衡每个节目通话:
- // [SVProgressHUD popActivity];
- SVProgressHUD.setDefaultStyle(.dark)
- SVProgressHUD.setDefaultAnimationType(.native)
- SVProgressHUD.setDefaultMaskType(.clear)
- SVProgressHUD.setMinimumSize(CGSize(width: 100, height: 100))
- SVProgressHUD.setCornerRadius(16.0)
- SVProgressHUD.setBackgroundColor("#000000".uiColor.withAlphaComponent(0.8))
- SVProgressHUD.setForegroundColor(.white)
- }
-
-
- public func setUIContent(font:UIFont? = nil,infoImage:UIImage? = nil) {
- if let font = font {
- SVProgressHUD.setFont(font)
- }
-
- if let infoImage = infoImage {
- SVProgressHUD.setInfoImage(infoImage)
- }
-
- }
- /// 显示文字提示
- public func showToast(text: String?, duration: TimeInterval = 3.0,containerView:UIView? = nil) {
- if let text = text {
- if text.count == 0 {
- return
- }
- kExecuteOnMainThread {
- if let containerView = containerView {
- SVProgressHUD.setContainerView(containerView)
- }
- SVProgressHUD.showInfo(withStatus: text)
- }
- }
- }
-
- /// 显示加载动画
- public func showLoading(text:String? = nil,containerView:UIView?) {
- kExecuteOnMainThread {
- // SVProgressHUD.dismiss()
- SVProgressHUD.setContainerView(containerView)
- SVProgressHUD.show(withStatus: text)
- }
- }
- /// 隐藏加载动画
- public func hideLoading() {
- kExecuteOnMainThread {
- SVProgressHUD.dismiss()
- }
- }
-
- /// 显示进度提示
- public func showProgress(progress:Float, status: String?,containerView:UIView?) {
- kExecuteOnMainThread {
-
- // if let containerView = containerView {
- SVProgressHUD.setContainerView(containerView)
- // }
-
- SVProgressHUD.showProgress(progress, status: status)
- }
- }
-
- /// 获取当前窗口,兼容 iOS 13 及以上版本
- static func getCurrentWindow() -> UIWindow? {
- if #available(iOS 13.0, *) {
- // iOS 13 及以上使用 `scene` 获取当前 window
- guard let scene = UIApplication.shared.connectedScenes.first(where: { $0.activationState == .foregroundActive }) as? UIWindowScene else {
- return UIApplication.shared.keyWindow
- }
- return scene.windows.first { $0.isKeyWindow }
- } else {
- // iOS 12 及以下直接从 keyWindow 获取
- return UIApplication.shared.keyWindow
- }
- }
- }
- public func kShowToastDataMissing(){
- TSToastShared.showToast(text: "Data missing")
- }
|