2017-08-15 50 views
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:]:這個類不是鍵值關鍵圖像兼容的編碼,」

我怎樣才能解決這個問題

謝謝

回答

0

SDCAlertView不支持添加圖標「開箱即用」,你將有一個圖像視圖添加到內容視圖。

這個問題的代碼應該讓你開始:Adding constraints in SDCAlertView

只要確保你添加的約束的內容查看作爲公認的答案提及。

+0

謝謝我的朋友 –