Add an Icon to the SDCAlertView

Home / Uncategorized / Add an Icon to the SDCAlertView

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 :

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

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


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


Read more

Leave a Reply

Your email address will not be published. Required fields are marked *