Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
436 views
in Technique[技术] by (71.8m points)

ios - Swift - UIAlert with image

I have this code:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try the below code in swift

saveAction.setValue(UIImage(named: "name.png").withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")

or try this

saveAction.setValue(zdjecieGlowne.withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...