【发布时间】:2020-12-01 21:07:30
【问题描述】:
我正在尝试在特定文本上添加字母间距。来自服务器的带有 HTML 标签的大文本,我只需要 P 标签的字母间距。但除了字母间距之外,一切正常。我错过了什么吗?有没有办法用属性文本做到这一点,还是需要用另一种解决方案来解决? 我目前已尝试以下示例:
let htmlCSSString = "<style>" +
"html *" +
"{" +
"font-size: 15px !important;" +
"font-family: Arial !important;" +
"text-align: justify;" +
"line-height: 1.5;" +
"text-justify: distribute;" +
"}" +
"p" +
"{" +
"font-size: 15px !important;" +
"font-family: Chap-Semibold !important;" +
"letter-spacing: 2.6px;" +
"color: white;" +
"text-align: center;" +
"}</style> \(text)"
guard let data = htmlCSSString.data(using: .utf8) else { return }
do {
let attributedStr = try NSMutableAttributedString(data: data, options: [.documentType: NSMutableAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue],documentAttributes: nil)
lb_details.attributedText = attributedStr
}
我不能使用 NSAttributedString.Key.kern 因为我不知道文本的范围.. 谁能解释一下为什么只有字母间距不起作用?
【问题讨论】:
标签: html swift nsattributedstring