Reputation: 445
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.
Upvotes: 2
Views: 5285
Reputation: 738
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
Upvotes: 3
Reputation: 53
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)
Upvotes: 3