CNLiveConfigAlertManager.swift
2.09 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
//
// CNLiveConfigAlertManager.swift
// metaCode
//
// Created by open on 2023/11/1.
//
import Foundation
typealias resultActionAlertBlock = (_ index: Int) -> Void
class ConfigAlertManager: NSObject {
static let shared = ConfigAlertManager()
/// 自定义弹框
open func presentAlert(title: String, message: String, actionTitles: NSArray, resultBlock: @escaping resultActionAlertBlock) {
let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
for title in actionTitles {
let style: UIAlertAction.Style
if title as! String == "取消" {
style = .cancel
} else {
style = .default
}
let action = UIAlertAction(title: title as? String, style: style) { action in
resultBlock(actionTitles.index(of: title))
}
alert.addAction(action)
}
currentViewController()?.present(alert, animated: true)
}
/// 自定义弹框 富文本
/// - Parameters:
/// - attrTitle: 标题
/// - attriMessage: 提示
/// - actionTitles: 动作按钮
/// - resultBlock: 返回
open func presentAlert(attrTitle: NSAttributedString,attriMessage: NSAttributedString, actionTitles: NSArray, resultBlock: @escaping resultActionAlertBlock) {
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
alert.setValue(attrTitle, forKey: "attributedTitle")
alert.setValue(attriMessage, forKey: "attributedMessage")
for title in actionTitles {
let style: UIAlertAction.Style
if title as! String == "取消" {
style = .cancel
} else {
style = .default
}
let action = UIAlertAction(title: title as? String, style: style) { action in
resultBlock(actionTitles.index(of: title))
}
alert.addAction(action)
}
currentViewController()?.present(alert, animated: true)
}
}