接收来自的HTML
类型。String
API
转换HTML
为NSAttributeString
->面对空白空间问题Unicode
-\u200b
如何从删除此空格HTML
来NSAttributeString
?
API响应:
{
"message" : "[<b>1-</b> Fill\U200b t\U200bhe \U200b\U200b\U200bBreak Do\U200bwn Table]"
}
结构-解码器:
{
"message" : "[<b>1-</b> Fill the Break Down Table]"
}
UILabel文字:
labet.text = Message.message // [<b>1-</b> Fill the Break Down Table] - SHOWING IN UI
UILabel属性文字:
labet.attributedText = Message.message.htmlAttributedString()
属性输出:
扩展码:
func htmlAttributedString() -> NSMutableAttributedString {
guard let data = self.data(using: String.Encoding.utf8, allowLossyConversion: false)
else { return NSMutableAttributedString() }
guard let formattedString = try? NSMutableAttributedString(data: data,
options: [.documentType: NSAttributedString.DocumentType.html,
.characterEncoding: String.Encoding.utf8.rawValue],
documentAttributes: nil )
else { return NSMutableAttributedString() }
return formattedString
}
有人可以指导我吗?如何避免这个空间?
试试这个:
labet.attributedText = Message.message.replacingOccurrences(of: "\u{200B}", with: "").htmlAttributedString()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句