1

I would like to add Share Image in alert message title instead of title text.
How can I implement this with swift 3?

let alertController = UIAlertController(title: "Share Movie", message: "Share this movie!", preferredStyle: .alert)

    alertController.addAction(UIAlertAction(title: "Share", style: UIAlertActionStyle.default, handler: nil))
Hamish
  • 74,809
  • 18
  • 177
  • 265
May Phyu
  • 885
  • 3
  • 19
  • 45
  • have you got an answer of your question or not? – Hardik Shekhat Mar 02 '17 at 13:17
  • I haven't try it yet bro @HardikShekhat. I will try it asap. I'm not well within these days. that's why. Thanks for asking me. :) I will reply the result. – May Phyu Mar 03 '17 at 03:56
  • Hello bro @HardikShekhat, I try your code now. Image appears within the alert box but I would like to show it in alert box title. Currently, I remove title text. So, how can I put that image in title place bro? – May Phyu Mar 03 '17 at 04:19
  • 1
    Bro @HardikShekhat, it is ok now. let alertController = UIAlertController(title:"", message:"\n I would like to share.", preferredStyle: .alert) and I adjust x, y value. Now, it is fine now bro. Thanks a lot. :) – May Phyu Mar 03 '17 at 04:52
  • I have tried below code before write answer. And it appears image in Title place. Maybe you have written something wrong? so, please check it again. – Hardik Shekhat Mar 03 '17 at 04:54
  • According to your code, Image appears in top left of the alert box. – May Phyu Mar 03 '17 at 05:05
  • you are right. I have put image in top left corner. you can edit code of my answer with your code if you want. – Hardik Shekhat Mar 03 '17 at 05:15
  • Hello bro @HardikShekhat, please could you look at this link http://stackoverflow.com/questions/42573338/swrevealviewcontroller-button-not-work-after-clicking-back-button-from-another-v . No one answer my question. I have to finish my project urgently. I know I should not write like this in here. But please help me if you know bro. – May Phyu Mar 03 '17 at 07:59

1 Answers1

7

Try this. Maybe help you.

let alert = UIAlertController(title: "Title", message: "Message", preferredStyle: .alert)

let action = UIAlertAction(title: "OK", style: .default, handler: nil)

let imgTitle = UIImage(named:"imgTitle.png")
let imgViewTitle = UIImageView(frame: CGRect(x: 10, y: 10, width: 30, height: 30))
imgViewTitle.image = imgTitle

alert.view.addSubview(imgViewTitle)
alert.addAction(action)

self.present(alert, animated: true, completion: nil)
Hardik Shekhat
  • 1,463
  • 10
  • 20
  • Hi bro @HardikShekhat bro , could you please check this link? http://stackoverflow.com/questions/42715152/add-image-into-uialertbox-in-swift-3 I also encountered another alert message problem :( – May Phyu Mar 10 '17 at 09:52