ios - NSAttributedString 添加自定义属性会丢失 html 标签
问题描述
假设我有一个来自 web 服务的字符串,它返回基本的 html。我想将它插入到具有自定义字体的 UITextView 中,但是在设置之后我丢失了例如标签。
let htmlString = "<b>This is a title</b><br/>Another line."
let attributedString = try? NSMutableAttributedString(
data: htmlString.data(using: String.Encoding.utf8) ?? Data(),
options: [
.documentType : NSAttributedString.DocumentType.html,
.characterEncoding : String.Encoding.utf8.rawValue
],
documentAttributes: nil
)
尽管字体超级小而不是我的字体,但这会呈现“好的”。设置属性后...
let attributes = [ NSAttributedStringKey.font: Fonts.raleway(ofSize: 17) ]
attributedString?.addAttributes(attributes, range: NSMakeRange(0, attributedString?.string.count ?? 0))
我失去了大胆。
有任何想法吗?
解决方案
推荐阅读
- azure - Azure 数据工厂 - 插入时继续冲突
- angular - 如何将 Angular Highcharts 添加到我的 Angular 项目中?
- javascript - 如何在自定义轮播上创建点?
- azure-data-factory - ADF 中的一个表达式生成器中的两个表达式
- r - 不同计算机上的回归输出不同
- pyspark - Azure Synpase - PySpark 地理处理形状文件
- ios - Cocoapods 安装权限错误有点严重
- python - 从列中随机选择值,然后在 Python 的另一列中删除具有该值的行
- json - Perl:来自导入 JSON 数据的哈希,Dumper 输出正确的数据,但是我无法访问它
- python - 已经在使用fillna,但在python中仍然有空值