如何使用图像创建 UIAlertView
How to create UIAlertView with Image
大家好,我有一个问题,是否可以在 Swift 中创建带图像的 UIAlertView,如何实现?如果有人可以帮助我,因为我在 swift 中没有在网络上找到一些示例,请在 objective c 中全部练习 iOS 6 而不是 iOS 7 或更高版本。谢谢。
在 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)
大家好,我有一个问题,是否可以在 Swift 中创建带图像的 UIAlertView,如何实现?如果有人可以帮助我,因为我在 swift 中没有在网络上找到一些示例,请在 objective c 中全部练习 iOS 6 而不是 iOS 7 或更高版本。谢谢。
在 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)