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:]:這個類不是鍵值關鍵圖像兼容的編碼,」)
我怎樣才能解決這個問題
謝謝
謝謝我的朋友 –