Hello everyone i have a question, if is possible to create UIAlertView with Image in Swift and how? If someone could help me because i don't find some example on network in swift practice all in objective c in iOS 6 not in iOS 7 or higher. Thanks.
Asked
Active
Viewed 5,279 times
2 Answers
3
After iOS8 UIAlertView
is deprecated so Apple recommends you to use UIAlertController
instead of UIAlertView
. And to accomplish what you asked you can look here

Efren
- 4,003
- 4
- 33
- 75

Sabrican Ozan
- 738
- 3
- 9
3
Here is a workaround that I used successfully.
let myImage = UIImage(name:"myImage")
let prevImage = UIImageView(frame: CGRect(x: 10, y: 50, width: 250, height: 172))
prevImage.image = myImage
let spacer = "\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
let previewController = UIAlertController(title: "PREVIEW", message: spacer, preferredStyle: .Alert)
let saveAction = UIAlertAction(title: "SAVE", style: .Default) { (UIAlertAction) in
self.uploadPatientPhoto(myImage!)
}
let retakeAction = UIAlertAction(title: "RETAKE", style: .Default) { (UIAlertAction) in
self.retakeNewPatientPhoto(self)
}
let cancelAction = UIAlertAction(title: "CANCEL", style: .Cancel, handler: nil)
previewController.addAction(saveAction)
previewController.addAction(retakeAction)
previewController.addAction(cancelAction)
previewController.view.addSubview(prevImage)
presentViewController(previewController, animated: true, completion: nil)

JMax
- 53
- 6
-
It's a shame that Apple didn't include a better way to add an image but this method breaks. From iOS8-iOS11. When the user has enabled larger text in their accessibility settings, the image interferes with the text. – user4806509 Aug 05 '17 at 21:57