4

i want to add image/icon to UIAlertController like the dialog inside apple music player

what i want colored/sized image/icon like the image below, not like the one inside this question .i believe its ios 11+ feature but i can't find the documents for it .

exactly like this :

enter image description here

can i do this in UIAlertController or i should make my own custom dialog uiviewcontroller ?

Kodr.F
  • 13,932
  • 13
  • 46
  • 91
  • @the4kman its not duplicated i saw the question in ur link , is has tiny images , the one i want is colored images with same size :) – Kodr.F Dec 19 '17 at 10:40
  • The answers address colorized images as well. – Tamás Sengel Dec 19 '17 at 10:41
  • can you show me the colorized images inside the options in ur answer ? – Kodr.F Dec 19 '17 at 10:41
  • @the4kman i will be waiting for ur answer of colored image in side the option in the link u've provided :) thanks – Kodr.F Dec 19 '17 at 10:47
  • Hi, You can add multiple button in the alert You can check out this tutorial http://blog.ijasoneverett.com/2016/04/add-custom-uibutton-to-uialertcontroller/ Hope this helps – Hitesh Sultaniya Dec 19 '17 at 11:02

1 Answers1

7
 let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)            
 alert.modalPresentationStyle = .popover


 let image = UIImage(named: "logoCircle")
 let imageView = UIImageView()
 imageView.image = image
 imageView.frame =  CGRect(x: 25, y: 18, width: 24, height: 24)
 alert.view.addSubview(imageView) 

 let image1 = UIImage(named: "icshare")
  let imageView1 = UIImageView()
  imageView1.image = image1
  alert.view.addSubview(imageView1)
  imageView1.frame = CGRect(x: 25, y: 75, width: 24, height: 24)

 let shareExternal = UIAlertAction(title: NSLocalizedString("Share External Link", comment: ""), style: .default) { action in
        }
 let shareInApp = UIAlertAction(title: "Share within", style: .default)   {
                action in
            } 

  alert.addAction(shareInApp)
  alert.addAction(shareExternal)


    if let presenter = alert.popoverPresentationController
    {
            presenter.sourceView = button
            presenter.sourceRect = button.bounds
    }
    present(alert, animated: true, completion: nil)
Uma Madhavi
  • 4,851
  • 5
  • 38
  • 73