【发布时间】:2015-09-04 12:02:06
【问题描述】:
大家好,我有一个问题,是否可以在 Swift 中使用 Image 创建 UIAlertView 以及如何创建?如果有人可以帮助我,因为我在 iOS 6 中的目标 c 中没有在 iOS 7 或更高版本中找到快速练习中的网络示例。谢谢。
【问题讨论】:
标签: ios swift uiimage uialertview
大家好,我有一个问题,是否可以在 Swift 中使用 Image 创建 UIAlertView 以及如何创建?如果有人可以帮助我,因为我在 iOS 6 中的目标 c 中没有在 iOS 7 或更高版本中找到快速练习中的网络示例。谢谢。
【问题讨论】:
标签: ios swift uiimage uialertview
在 iOS8 UIAlertView 被弃用之后,Apple 建议您使用 UIAlertController 而不是 UIAlertView。为了完成你的要求,你可以查看here
【讨论】:
这是我成功使用的解决方法。
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)
【讨论】: