Guest User

Untitled

a guest
Jan 18th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. @objc extension UIAlertController {
  2.  
  3. static func showAlert(title: String?, message: String? = nil, closeActionTitle: String? = "OK", preferredStyle: UIAlertControllerStyle = .alert, actions: [UIAlertAction]? = nil) {
  4. let alertController = UIAlertController(title: title,
  5. message: message,
  6. preferredStyle: preferredStyle)
  7. var allActions = [UIAlertAction]()
  8. if let closeTitle = closeActionTitle {
  9. allActions.append(UIAlertAction(title: closeTitle, style: .cancel))
  10. }
  11. allActions.append(contentsOf: actions ?? [])
  12. allActions.forEach { alertController.addAction($0) }
  13.  
  14. let vc = ClearViewController()
  15. let window = UIWindow(frame: UIScreen.main.bounds)
  16. window.rootViewController = vc
  17. window.backgroundColor = AppTheme.color.clear
  18. window.windowLevel = UIWindowLevelAlert
  19.  
  20. DispatchQueue.main.async {
  21. window.makeKeyAndVisible()
  22. vc.present(alertController, animated: true)
  23. }
  24. }
Add Comment
Please, Sign In to add comment