user1.develop
user1.develop

Reputation: 15

Add image in the message box (UIAlertController)

I'm using UIAlertController() how can I add just title and image in the my message box like this:

enter image description here

Upvotes: 1

Views: 1182

Answers (1)

Shah Nilay
Shah Nilay

Reputation: 798

Swift 3.0

Use below code

let alertMessage = UIAlertController(title: "My Title", message: "\n\n\n\n\n\n\n\n\n\n\n\n", preferredStyle: .alert)
let action = UIAlertAction(title: "OK", style: .default, handler: nil)
alertMessage .addAction(action)
self.present(alertMessage, animated: true, completion: nil)

let xPosition = self.view.frame.origin.x + 80
let imageView = UIImageView(frame: CGRect(x: xPosition, y: 100, width: 100, height: 100))
imageView.image = #imageLiteral(resourceName: "test.png")
alertMessage.view.addSubview(imageView)

Without "OK" button you cannot to close above alertMessage.
Set xPosition and y of imageViewand message of alertMessage as per your requirement.

Upvotes: 2

Related Questions