Cannot convert value of type NSAttributedString.DocumentAttributeKey to .DocumentReadingOptionKey

前端 未结 8 1965
鱼传尺愫
鱼传尺愫 2020-12-09 07:18

I found this string extension somewhere on SO that allows me to turn html code into an attributed string:

func html2AttributedString() -> NSAttributedStri         


        
相关标签:
8条回答
  • 2020-12-09 08:21

    I use NSAttributedStringKey and had similar error "Cannot convert value of type" on Swift 4. In case anyone using NSAttributedStringKey comes here looking for an answer, this is how I fixed:

    let TextStroke: [NSAttributedStringKey : Any] = [
        NSAttributedStringKey(rawValue: NSAttributedStringKey.strokeColor.rawValue) : UIColor.black,
        NSAttributedStringKey(rawValue: NSAttributedStringKey.foregroundColor.rawValue) : UIColor.white,
        NSAttributedStringKey(rawValue: NSAttributedStringKey.strokeWidth.rawValue) : -6.0,]
    

    And this is how I add the attribute to the text:

    myLabel.attributedText = NSAttributedString(string: myString, attributes: TextStroke)
    
    0 讨论(0)
  • 2020-12-09 08:24

    Use NSAttributedString.DocumentType.html

    NSMutableAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html] , documentAttributes: nil)
    
    0 讨论(0)
提交回复
热议问题