Ios 将映像添加到UIAlertController
我想向UIAlertController添加一个映像。图像不需要在按钮上,只显示在控制器的中间。我的代码如下所示,但由于消息“未识别的选择器已发送到实例”而崩溃Ios 将映像添加到UIAlertController,ios,swift,uialertcontroller,unrecognized-selector,Ios,Swift,Uialertcontroller,Unrecognized Selector,我想向UIAlertController添加一个映像。图像不需要在按钮上,只显示在控制器的中间。我的代码如下所示,但由于消息“未识别的选择器已发送到实例”而崩溃 不幸的是,苹果不允许我们向UIAlertController或UIAlertView添加图像。这些API仅限于苹果的人机界面指南 如果您真的需要在类似于UIAlertController-的对话框中使用图像,我建议您尝试使用类似以下内容。什么是无法识别的选择器?如果不可能,则不可能!将不得不使用一个视图控制器,然后…有一种方法可以做到这
不幸的是,苹果不允许我们向
UIAlertController
或UIAlertView
添加图像。这些API仅限于苹果的人机界面指南
如果您真的需要在类似于
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)
}