|
@@ -9,6 +9,7 @@ public extension UIViewController {
|
|
|
func showCustomAlert(
|
|
|
title: String? = "",
|
|
|
message: String?,
|
|
|
+ rightActionString:String = "Delete".localized,
|
|
|
deleteHandler: (() -> Void)? = nil,
|
|
|
cancelHandler: (() -> Void)? = nil
|
|
|
) {
|
|
@@ -40,7 +41,7 @@ public extension UIViewController {
|
|
|
}
|
|
|
alert.addAction(cancelAction)
|
|
|
|
|
|
- let deleteAction = UIAlertAction(title: "Delete".localized, style: .destructive) { _ in
|
|
|
+ let deleteAction = UIAlertAction(title: rightActionString, style: .destructive) { _ in
|
|
|
deleteHandler?()
|
|
|
}
|
|
|
alert.addAction(deleteAction)
|
|
@@ -101,6 +102,53 @@ public extension UIViewController {
|
|
|
// 显示弹窗
|
|
|
present(alert, animated: true, completion: nil)
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ func showDeleteErrorAlert(
|
|
|
+ title: String? = "",
|
|
|
+ message: String?,
|
|
|
+ deleteHandler: (() -> Void)? = nil,
|
|
|
+ cancelHandler: (() -> Void)? = nil
|
|
|
+ ) {
|
|
|
+ let alert = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
|
|
|
+
|
|
|
+ // 自定义标题
|
|
|
+ if let title = title {
|
|
|
+ let titleAttributes: [NSAttributedString.Key: Any] = [
|
|
|
+ .font: UIFont.boldSystemFont(ofSize: 20),
|
|
|
+ .foregroundColor: UIColor.white
|
|
|
+ ]
|
|
|
+ let attributedTitle = NSAttributedString(string: title, attributes: titleAttributes)
|
|
|
+ alert.setValue(attributedTitle, forKey: "attributedTitle")
|
|
|
+ }
|
|
|
+
|
|
|
+ // 自定义消息
|
|
|
+ if let message = message {
|
|
|
+ let messageAttributes: [NSAttributedString.Key: Any] = [
|
|
|
+ .font: UIFont.boldSystemFont(ofSize: 17),
|
|
|
+ .foregroundColor: UIColor.white
|
|
|
+ ]
|
|
|
+ let attributedMessage = NSAttributedString(string: message, attributes: messageAttributes)
|
|
|
+ alert.setValue(attributedMessage, forKey: "attributedMessage")
|
|
|
+ }
|
|
|
+
|
|
|
+ // 添加按钮
|
|
|
+ let cancelAction = UIAlertAction(title: "Retain".localized, style: .cancel) { _ in
|
|
|
+ cancelHandler?()
|
|
|
+ }
|
|
|
+ alert.addAction(cancelAction)
|
|
|
+
|
|
|
+ let deleteAction = UIAlertAction(title: "Delete".localized, style: .destructive) { _ in
|
|
|
+ deleteHandler?()
|
|
|
+ }
|
|
|
+ alert.addAction(deleteAction)
|
|
|
+
|
|
|
+ // 设置黑暗模式
|
|
|
+ alert.overrideUserInterfaceStyle = .dark
|
|
|
+
|
|
|
+ // 显示弹窗
|
|
|
+ present(alert, animated: true, completion: nil)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|