1

I installed the SDCAlertView to my project from cocoapods because I need to add an icon with a text on the left hand side alertAction, I have a question about how can i add an image (icon) to the AlertAction on the left hand side in my SDCAlertView? Here is my code :

func alert() {

    let alertController = AlertController(title: "Alert Controller", message: "Message For Alert", preferredStyle: .actionSheet)
    let alertCancel = AlertAction(title: "Cancel", style: .preferred, handler: nil)
    let alertOK = AlertAction(title: "OK", style: .normal, handler: nil)


            let paragraphStyle = NSMutableParagraphStyle()
            // Here is the key thing!
            paragraphStyle.alignment = .left

            let messageText = NSMutableAttributedString(
                string: "Video",
                attributes: [
                    NSParagraphStyleAttributeName: paragraphStyle,
                    NSFontAttributeName : UIFont.preferredFont(forTextStyle: .headline),
                    NSForegroundColorAttributeName : UIColor.black
                ]
            )


    let image = UIImage(named: "video.png")
    alertOK.setValue(image, forKey: "image")

    alertOK.setValue(messageText, forKey: "attributedTitle")

    alertController.add(alertOK)
    alertController.add(alertCancel)
    alertController.present()
}

but i get this error message ('[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key image.')

How can I fix this issue

Thank You

Hamza Hassan
  • 107
  • 1
  • 10

1 Answers1

0

SDCAlertView does not support adding an icon "out of the box", you will have to add an image view to the content view.

This question's code should get you started: Adding constraints in SDCAlertView

Just make sure you add the constraints to the contentView as mentioned in the accepted answer.

idz
  • 12,825
  • 1
  • 29
  • 40