将图像添加到UIAlertController

我想将图像添加到UIAlertController。 图像不需要在按钮上,只需在控制器中间显示。 我的代码如下,但崩溃的消息“无法识别的选择器发送到实例”。

func showAlert () { let alert = UIAlertController(title: "Title of Alert", message: "none", preferredStyle:UIAlertControllerStyle.ActionSheet) // add an image let image = UIImage(named: "example") var imageView = UIImageView(image: image) imageView.frame = CGRectMake(0, 0, 100, 100) var imageAction = UIAlertAction(title: "", style:.Default, handler: nil) imageAction.setValue(imageView, forKey: "image") alert.addAction(imageAction) // add a continue button var action = UIAlertAction(title: "Continue", style:.Default, handler: {(alert:UIAlertAction!) in self.continue() }) alert.addAction(action) // show the UIAlertController self.presentViewController(alert, animated: true, completion: nil) } 

不幸的是,Apple不允许我们将图像添加到UIAlertControllerUIAlertView 。 这些API仅限于Apple的人机界面指南。

如果你真的需要像UIAlertController的对话框中的图像,我建议尝试使用像https://github.com/wimagguc/ios-custom-alertview这样的东西。