Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

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

1 Answer

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")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...