Swift - 带有图像的 UIAlert [英] Swift - UIAlert with image
本文介绍了Swift - 带有图像的 UIAlert的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个代码:
var zdjecieGlowne: UIImage? = nil
let alert = UIAlertController(title:"MyTitle", message: "My Message Box ", preferredStyle: UIAlertControllerStyle.alert)
let saveAction = UIAlertAction(title: "MyTitle", style: .default, handler: nil)
//saveAction.setValue(UIImage(named: "logo")?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")
saveAction.setValue(zdjecieGlowne, forKey: "image")
dump(zdjecieGlowne)
alert.addAction(saveAction)
alert.addAction(UIAlertAction(title: "Option 1", style: UIAlertActionStyle.default, handler: { alertAction in
//alert.dismiss(animated: true, completion: nil)
print("1 pressed")
}))
alert.addAction(UIAlertAction(title: "Option 2", style: UIAlertActionStyle.default, handler: { alertAction in
//alert.dismiss(animated: true, completion: nil)
print("2 pressed")
}))
alert.addAction(UIAlertAction(title: "Option 3", style: UIAlertActionStyle.default, handler: { alertAction in
//alert.dismiss(animated: true, completion: nil)
print("3 pressed")
}))
self.present(alert, animated: true, completion: nil)
因此,我收到带有蓝色背景而不是图片的警报.为什么会这样?
As a result, I receive Alert with a blue background instead of a picture. Why is it like that?
推荐答案
在 swift 中试试下面的代码
Try the below code in swift
saveAction.setValue(UIImage(named: "name.png").withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")
或者试试这个
saveAction.setValue(zdjecieGlowne.withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")
这篇关于Swift - 带有图像的 UIAlert的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文