html - Swift NSAttribured String CSS 属性宽度不起作用
问题描述
我有 HTML 文本,我想将其转换为 NSAttributedString,一切正常,但有一个问题,我想在左侧显示带有垂直线的 blockquote 标记,我希望这条线的宽度为 3px,但似乎宽度被忽略。如何更改此 div 的宽度?这是我的代码。我做错了什么?
public class func NSStringToAttributed(_ nsText: String,
font: UIFont = UIFont.systemFont(ofSize: 15.0)) -> NSMutableAttributedString? {
let stringWithFont = (NSString(string: nsText).appendingFormat("<style>body{font-family: '%@'; font-size:%fpx;}</style>",
".SFUIText",
font.pointSize))
let parsedCommentHTML = stringWithFont.replacingOccurrences(of: "<blockquote>",
with: "<div style=\"max-width: 3px; background: #82a43a; height: transform:translateY();\"><i style=\"color:#A9A9A9\"><blockquote>\n").replacingOccurrences(of: "</blockquote>",
with: "</blockquote></i></div>")
if let data = String(parsedCommentHTML).data(using: .unicode,
allowLossyConversion: false) {
let style = NSMutableParagraphStyle()
style.minimumLineHeight = 20.0
style.headIndent = 6.0
style.firstLineHeadIndent = 6.0
style.alignment = .left
let attributes = [
NSParagraphStyleAttributeName: style ]
if let attrString = try? NSMutableAttributedString(data: data,
options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil) {
attrString.addAttributes(attributes,
range: NSString(string: attrString.string).range(of: attrString.string))
attrString.addAttribute(NSKernAttributeName,
value: -0.2,
range: NSString(string: attrString.string).range(of: attrString.string))
return attrString
}
}
解决方案
推荐阅读
- javascript - 带有对话框的 FileSaver.js
- machine-learning - 协作过滤添加新用户和项目
- javascript - Ckeditor - 在“选择”字段中加载动态字段值
- c# - 使用 Partner Soap Api 在 Salesforce 中获取联系人的帐户信息
- c# - 如何在运行时更改补间动画的 endValueString?
- spring-boot-admin - spring boot 管理日志文件显示 e.headers ['content-range']
- angular - VSTS 轰炸 NPM 安装?
- hadoop - 在 hadoop 安装期间无法运行纱线
- python - Parallels VM 中 Django 应用的 Ghost NoReverseMatch 错误
- rust - 如何根据库功能设置依赖项的功能?