CNLiveTips.swift
3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//
// CNLiveTips.swift
// metaCode
//
// Created by open on 2023/6/5.
//
import Foundation
import UIKit
import YYCategories
import MBProgressHUD
class tip {
static func showMessage(message : String) {
if !message.isNotBlank() {
return
}
let delegate = UIApplication.shared.delegate as! AppDelegate
let bgView = UIView.init()
bgView.backgroundColor = UIColor(white: 0.1, alpha: 0.7)
bgView.layer.cornerRadius = 8.0
bgView.clipsToBounds = true
delegate.window?.addSubview(bgView)
let remindLab = UILabel.init()
remindLab.textColor = .white
remindLab.font = Font_15_Fit
remindLab.textAlignment = .center
remindLab.numberOfLines = 1
remindLab.backgroundColor = .clear
remindLab.text = message
bgView.addSubview(remindLab)
var width = message.boundingRect(with: CGSize(width: CGFloat(MAXFLOAT), height: delegate.window?.bounds.size.height ?? 0), options:.usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font:Font_15_Fit], context: nil).size.width
if width > (delegate.window?.bounds.size.width ?? 0)/4.0 * 3.0 {
width = (delegate.window?.bounds.size.width ?? 0)/4.0 * 3.0
}
let height = message.boundingRect(with: CGSize(width: width, height: CGFloat(MAXFLOAT)), options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font:Font_15_Fit], context: nil).size.height
bgView.bounds = CGRect(x: 0, y: 0, width: width + 20, height: height + 20)
bgView.layer.position = CGPoint(x: (delegate.window?.bounds.size.width ?? 0) / 2.0, y: ( (delegate.window?.bounds.size.height ?? 0) - CNLiveConfigManager.shared.keyboardDisplayHeight) / 2.0)
remindLab.bounds = CGRect(x: 0, y: 0, width: width, height: height)
remindLab.layer.position = CGPoint(x: bgView.bounds.size.width / 2, y: bgView.bounds.size.height / 2)
UIView.animate(withDuration: 1, delay: 1, options: .curveEaseOut) {
bgView.alpha = 0
} completion: { finish in
bgView.removeFromSuperview()
}
}
static func showLoading(message: String) {
let delegate = UIApplication.shared.delegate as! AppDelegate
delegate.window?.subviews.forEach({ view in
if view.isKind(of: MBProgressHUD.layerClass) {
let hub = view as! MBProgressHUD
hub.removeFromSuperview()
}
})
let hub = MBProgressHUD.showAdded(to: delegate.window!, animated: true)
hub.mode = .indeterminate
hub.animationType = .fade
hub.contentColor = .white
hub.bezelView.backgroundColor = .black
hub.label.textColor = .white
if message.isNotBlank() {
hub.label.text = message
}
}
static func hiddenLoading() {
let delegate = UIApplication.shared.delegate as! AppDelegate
MBProgressHUD.hide(for: delegate.window!, animated: true)
}
}