gpt4 book ai didi

ios - 将图像添加到警报 View

转载 作者:IT王子 更新时间:2023-10-29 05:24:46 26 4
gpt4 key购买 nike

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

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

警报 View 代码

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)

ImageView 代码

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

最佳答案

是的,您可以添加一个 UIImageView 作为您的警报 View 的 subview 。

var imageView = UIImageView(frame: CGRect(x: 220, y: 10, width: 40, height: 40))
imageView.image = yourImage

alert.view.addSubview(imageView)

关于ios - 将图像添加到警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28340836/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com