I have an alert view that pops up when the user press the add button. How do i add an image to the alert view?
I added some code that i took reference from stack overfl
We can add image as one option in alert view controller like this.
let imageView = UIImageView(frame: CGRect(origin: CGPoint(x: 0,y :0), size: CGSize(width: 196, height: 196)))
imageView.image = image
UIGraphicsBeginImageContextWithOptions(imageView.bounds.size, imageView.isOpaque, 0.0)
defer { UIGraphicsEndImageContext() }
let context = UIGraphicsGetCurrentContext()
imageView.layer.render(in: context!)
let finalImage = UIGraphicsGetImageFromCurrentImageContext()
let alertMessage = UIAlertController(title: "Your Title", message: "", preferredStyle: .alert)
let action = UIAlertAction(title: "", style: .default, handler: nil)
action.setValue(finalImage?.withRenderingMode(UIImageRenderingMode.alwaysOriginal), forKey: "image")
alertMessage .addAction(action)
let action1 = UIAlertAction(title: "OK", style: .default, handler: nil)
alertMessage .addAction(action1)
self.present(alertMessage, animated: true, completion: nil)