问题描述:

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.

网友答案:

After iOS8 UIAlerView is deprecated so Apple would recommend you to use UIAlertController instead of UIAlertView. And to accomplish what you asked you can look here

网友答案:

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)
相关阅读:
Top