How to add alert message to a global class

后端 未结 5 1299
刺人心
刺人心 2021-01-26 09:29

I have the following code repeated in many of my view controllers. I would like to refactor it into a global class/view controller. However, I still want it to be s

5条回答
  •  逝去的感伤
    2021-01-26 10:12

    You can use SCLAlertView for simple alert creation. The alert is always shown from the current view controller and returns to this controller when the alert is closed. This static function shows a simple message with an OK button. Of course, you can also add text fields, buttons and other elements. These alerts are especially nice because you can call them at any point in your code, even from background queues.

    class Alerts {
    
        static func showAlert(title: String, message: String) {
            DispatchQueue.main.async {
                let alert = SCLAlertView()
                alert.showCustom(title, subTitle: message, color: UIColor.blue, icon: UIImage(named: "logo")!, closeButtonTitle: "OK")
            }
        }
    
    }
    

提交回复
热议问题