【发布时间】:2015-07-29 18:54:15
【问题描述】:
见下文:
// Description (HTML string):
var attrStr = NSMutableAttributedString(
data: formatted.dataUsingEncoding(NSUnicodeStringEncoding, allowLossyConversion: true)!,
options: [ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType],
documentAttributes: nil,
error: nil)
var paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.Justified
attrStr?.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSMakeRange(0, attrStr!.length))
attrStr?.addAttribute(NSKernAttributeName, value: -0.1, range: NSMakeRange(0, attrStr!.length))
descLabel.attributedText = attrStr
descLabel.sizeToFit()
到目前为止,我所有为文本辩护的尝试都导致了相同的行为。我尝试过通过内联样式的 CSS int eh html 文本,或使用 textAlignment 属性。
问题是,对齐文本会破坏字母间距(实际上它会增加每个单词的跟踪/字距调整,而不仅仅是增加中间的空间)。
见:
我希望看到一个不是 hack 的解决方案,因为我自己设计了一些 hack,但是我陷入了其他问题的太多可能性。
我错过了一些简单的东西吗?我已经浏览了所有的 UI 选项,正如我的代码示例中所见,我什至尝试更改 Kern,它确实会改变,但只是按比例改变(即它仍然会增加)。
【问题讨论】: