0
我想在UIAlertbox中添加图像,以便添加以下代码。
如何在Swift 3中将图像添加到UIAlertbox中?
let alertController = UIAlertController(title: "Gender", message: "" , preferredStyle: .alert)
// Create the actions
let okAction = UIAlertAction(title: "Female", style: UIAlertActionStyle.default) {
UIAlertAction in
// exit(0)
debugPrint("Press OK")
}
let cancelAction = UIAlertAction(title: "Male", style: UIAlertActionStyle.cancel) {
UIAlertAction in
}
// Add the actions
okAction.setValue(#imageLiteral(resourceName: "female_image"), forKey: "image")
cancelAction.setValue(#imageLiteral(resourceName: "male_image"), forKey: "image")
alertController.addAction(okAction)
alertController.addAction(cancelAction)
当我运行应用程序,只有一个形象出现。这有什么问题?
请大家帮帮我吗?
你好兄弟@seggy,你的代码工作!非常感谢。但是,我想编辑图像大小。所以,我添加了这些代码。让femaleimgView = UIImageView(frame:CGRect(x:10,y:10,width:30,height:30))和femaleimgView.image = femaleimage。 Action1.setValue(femaleimgView,forKey:“image”)。当我添加这些代码时,我得到了错误。 :( –
让我检查.... – seggy
是否对你有用? – seggy