How to add a picture in UIAlertController?

let alertController = UIAlertController(title: "Hey", message: "My Image:", preferredStyle: .Alert) alertController.view.subviews.first?.subviews.first?.backgroundColor = UIColor(red: 90.0, green: 70.0, blue: 255.0, alpha: 0.1) alertController.view.subviews.first?.subviews.first?.layer.cornerRadius = 10 alertController.view.tintColor = UIColor.blueColor() alertController.addAction(UIAlertAction(title: "Ok", style: .Default) { action in let scene = ProgressScene(fileNamed: "GameScene")! self.view?.presentScene(scene, transition: SKTransition.flipHorizontalWithDuration(0.3)) }) self.view?.window?.rootViewController?.presentViewController(alertController, animated: true, completion: nil) 

  • Add a picture of the UIAlertController itself, as it should be, there is an option to add a picture to the UIAlertAction. will arrange it? - Max Mikheyenko
  • but no, you can. I can’t figure out how to expand the whole controller so that the picture is normally located in the layout - Max Mikheyenko
  • I'm trying to at least set her size - Leci
  • if you give her the size, you ’ll get something like this: (see the position of the asterisk) i.stack.imgur.com/0v2UU.png - Max Mikheyenko
  • Understood, thanks) - Leci

1 answer 1

You can do this:

 let image = UIImage(named: "myAlertImage") var action = UIAlertAction(title: "title", style: .Default, handler: nil) action.setValue(image, forKey: "image") alertController.addAction(action)