2017-08-15 52 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

谢谢我的朋友 –