2

Yes I am Aware that I can add images using this code. And I've tried playing with it.

let alertController = UIAlertController(title: nil, message: nil, preferredStyle: .ActionSheet)
let action = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil)
action.setValue(UIImage(named: "someImage.png"), forKey: "image")
alertController.addAction(action)
view.presentViewController(alertController, animated: true, completion: nil)

Which would result to an alert controller looking like this.

enter image description here

took the image from this post How can i customize UIAlertAction in UIAlertController for iOS8?

enter image description here

like on this post Action Sheet Button text alignment, but UIAlertActionSheet is deprecated and Swift docs says that I should use UIAlertController now.

I've also read this post UIAlertController custom font, size, color

and seeing the first answer

// this has to be set after presenting the alert, otherwise the internal property __representer is nil
guard let label = action.valueForKey("__representer")?.valueForKey("label") as? UILabel else { return }
label.attributedText = attributedText

this code can only be executed after the alert has been presented. But I need to add the image before presenting the alert controller. any idea guys?

Community
  • 1
  • 1
Zonily Jame
  • 5,053
  • 3
  • 30
  • 56

0 Answers0