在swift中将图像添加到UIAlertController中

daa*_*aal 3 image swift uialertcontroller

我想要一个带有图像的简单UIAlertController.我该怎么办?

let alertMessage = UIAlertController(title: "Service Unavailable", message: "Please retry later", preferredStyle: .Alert)
                alertMessage.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
                self.presentViewController(alertMessage, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

Mru*_*nal 11

试试这个:

let alertMessage = UIAlertController(title: "Service Unavailable", message: "Please retry later", preferredStyle: .Alert)

let image = UIImage(named: "myImage")
var action = UIAlertAction(title: "OK", style: .Default, handler: nil)
action.setValue(image, forKey: "image")
alertMessage .addAction(action)

self.presentViewController(alertMessage, animated: true, completion: nil)
Run Code Online (Sandbox Code Playgroud)

  • 不要认为这种方法有效 (4认同)