Display AlertController with Image in Swift (XCODE 8.3)

Last Updated: May 2, 2018

In this article we will see how we can add image to Alert Controller in iOS app

You can show the UIAlertController with UIImage in iOS Apps.
Following image shows how you can show the image on UIAlertController

Now you can use the following code to implement above Alert View

      let uiAlertControl = UIAlertController(title: "Photo", message: "Photo of the Day", preferredStyle: .alert)
        let uiImageAlertAction = UIAlertAction(title: "", style: .default, handler: nil)
        let image = #imageLiteral(resourceName: "StockSnap_AWEH8SQCHN")
        // size the image
        let maxsize =  CGSize(width: 245, height: 300)
        let scaleSze = CGSize(width: 245, height: 245/image.size.width*image.size.height)
        let reSizedImage = image.resize(newSize: scaleSze)
        uiImageAlertAction.setValue(reSizedImage.withRenderingMode(.alwaysOriginal), forKey: "image")
        uiAlertControl.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
        self.present(uiAlertControl, animated: true, completion: nil)