1
我将SDCAlertView从cocoapods安装到我的项目中,因为我需要在左边添加一个带有文本的图标alertAction,我有一个关于如何添加图像(图标)到在我的SDCAlertView中左边的AlertAction? 这里是我的代码:向SDCAlertView添加一个图标
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()
}
,但我得到这个错误消息(“[setValue方法:forUndefinedKey:]:这个类不是键值关键图像兼容的编码,”)
我怎样才能解决这个问题
谢谢
谢谢我的朋友 –