我想在textView中粘贴HTML文本(带有p,br,bgcolor等).我确实试过了下一个:
var bodyText = NSAttributedString(data: body.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType], documentAttributes: nil, error: nil)
postBody.text = bodyText
Run Code Online (Sandbox Code Playgroud)
postBody - > textView.但它会打印下一个错误:
Cannot assign a value of type 'NSAttributedString?' to a value of type 'String!'
如何在textView中正确打印?
而不是text,使用attributedText.
postBody.attributedText = bodyText
Run Code Online (Sandbox Code Playgroud)
或者,如果您只想要没有属性的文本,请使用NSAttributedString's string属性.
postBody.text = bodyText?.string
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1406 次 |
| 最近记录: |