SWIFT – 添加图像以提醒视图
我有一个警告视图,当用户按下添加button时popup。 如何将图像添加到警报视图?
我添加了一些我从堆栈溢出引用的代码。 我的保存button被replace为图像,图像显示为蓝色…
警报视图代码
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
作为你的alertview的子视图。
var imageView = UIImageView(frame: CGRectMake(220, 10, 40, 40)) imageView.image = yourImage alert.view.addSubview(imageView)