我有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
}
}