Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 在swift中将图像添加到UIAlertController中_Image_Swift_Uialertcontroller - Fatal编程技术网

Image 在swift中将图像添加到UIAlertController中

Image 在swift中将图像添加到UIAlertController中,image,swift,uialertcontroller,Image,Swift,Uialertcontroller,我想有一个简单的UIAlertController与图像在它。我该怎么办 let alertMessage = UIAlertController(title: "Service Unavailable", message: "Please retry later", preferredStyle: .Alert) alertMessage.addAction(UIAlertAction(title: "OK", style: .Default, handler:

我想有一个简单的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)

我认为无法将映像添加到UIAlertController。

尝试以下方法:

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)

这是我在“警报”视图中显示图像的代码

var logoAlert = UIImageView(frame: CGRectMake(0, 0, 300, 250))
    logoAlert.image = UIImage(named: "v1.png")

    infoController.view.addSubview(logoAlert)
    NSLog("image is draw")
logoalert正在发送数据 infoController-是fun的名称 重新命名,一切都会好起来的
将此代码粘贴到alert controller的乐趣中

一段适用于我的代码:

func alert2 (heading: String,image: String){
        if self.presentedViewController == nil {
            let alertController = UIAlertController(title: nil,     message: " ", preferredStyle: .Alert )
            var imageView = UIImageView(frame: CGRectMake(10, 6, 300, 50))
            imageView.image = UIImage(named: display.0)
            alertController.view.addSubview(imageView)
            alertController.addAction(UIAlertAction(title: "Maps", style: UIAlertActionStyle.Default, handler: {(action:UIAlertAction!) in self.makeContact("maps")}))

欢迎来到StackOverflow!如果您将答案编辑为可读的英文描述(而不是“dtring”、“fun”),则更容易理解并增加人们投票的机会。:-)我不知道你之前是怎么得到否决票的,但是你已经修复了它,你的代码为meThis工作,有效地将图像添加到警报视图的按钮区域。这不是正确的方法。影响按钮大小,可能缺少可访问性。如果没有苹果提供的简单方法,定制警报更有效。