将图像添加到警报视图 [英] Add image to alert view

查看:108
本文介绍了将图像添加到警报视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个警报视图,当用户按下添加按钮时会弹出。如何将图像添加到警报视图?

I have an alert view that pops up when the user press the add button. How do i add an image to the alert view?

我添加了一些我从堆栈溢出引用的代码。我的保存按钮被替换为图像,图像显示为蓝色...

I added some code that i took reference from stack overflow. My save button is replaced with the image and the image appear to be in blue colour...

警报视图代码

var alert = UIAlertController(title: "Spring Element \(springNumber)",
            message: "Add spring properties",
            preferredStyle: .Alert)

        let saveAction = UIAlertAction(title: "Save",
            style: .Default) { (action: UIAlertAction!) -> Void in

                let textField1 = alert.textFields![0] as UITextField
                self.txtField1.append(textField1.text)
                self.tableView.reloadData()

                let textField2 = alert.textFields![1] as UITextField
                self.txtField2.append(textField2.text)
                self.tableView.reloadData()

                println(self.txtField1)
                println(self.txtField2)
        }

        let cancelAction = UIAlertAction(title: "Cancel",
            style: .Default) { (action: UIAlertAction!) -> Void in
        }

        //adding textfield1
        alert.addTextFieldWithConfigurationHandler {
            (textField1: UITextField!) -> Void in
            textField1.placeholder = "Force"
        }

        //adding textfield2
        alert.addTextFieldWithConfigurationHandler {
            (textField2: UITextField!) -> Void in
            textField2.placeholder = "Stiffness"
        }

        alert.addAction(saveAction)
        alert.addAction(cancelAction)

        presentViewController(alert,
            animated: true,
            completion: nil)

图像视图代码

   let image = UIImage(named: "springAtWall")
    saveAction.setValue(image, forKey: "image")
    alert.addAction(saveAction)


推荐答案

是的,您可以将 UIImageView 作为子视图添加到您的提醒视图。

Yes, you can add a UIImageView as a subview to your alertview.

var imageView = UIImageView(frame: CGRectMake(220, 10, 40, 40))
imageView.image = yourImage

alert.view.addSubview(imageView)

这篇关于将图像添加到警报视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆