Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @objc extension UIAlertController {
- static func showAlert(title: String?, message: String? = nil, closeActionTitle: String? = "OK", preferredStyle: UIAlertControllerStyle = .alert, actions: [UIAlertAction]? = nil) {
- let alertController = UIAlertController(title: title,
- message: message,
- preferredStyle: preferredStyle)
- var allActions = [UIAlertAction]()
- if let closeTitle = closeActionTitle {
- allActions.append(UIAlertAction(title: closeTitle, style: .cancel))
- }
- allActions.append(contentsOf: actions ?? [])
- allActions.forEach { alertController.addAction($0) }
- let vc = ClearViewController()
- let window = UIWindow(frame: UIScreen.main.bounds)
- window.rootViewController = vc
- window.backgroundColor = AppTheme.color.clear
- window.windowLevel = UIWindowLevelAlert
- DispatchQueue.main.async {
- window.makeKeyAndVisible()
- vc.present(alertController, animated: true)
- }
- }
Add Comment
Please, Sign In to add comment