在iOS(Swift或Objective-C)中对齐文本而不会破坏跟踪/字距调整/字母间距

见下文:

// 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() 

到目前为止,我试图certificate文本的合理性,导致了同样的行为。 我尝试过内联式CSS int eh html文本,或者使用textAlignment属性。

问题是,certificate文本的合理性会打破字母间距(实际上它会增加每个单词的跟踪/字距,而不是仅增加其间的空间)。

看到: 在此处输入图像描述

我想看到一个不是黑客攻击的解决方案,因为我已经设计了一些自己的黑客攻击,但后来我陷入了其他问题的太多可能性。

我错过了一些简单的东西? 我已经浏览了所有的UI选项,并且在我的代码示例中看到,我甚至尝试更改Kern,它确实发生了变化,但只是按比例变化(即它仍然增加)。

您是否尝试使用hyphenationFactor为1添加NSParagraphStyle属性?

这将保持您的字距和单词间距,但是当单词需要中断到下一行时会添加连字符。