Tcacenco Daniel
Tcacenco Daniel

Reputation: 445

How to create UIAlertView with Image

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

Answers (2)

Sabrican Ozan
Sabrican Ozan

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

JMax
JMax

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

Related Questions