6
見下文:對齊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()
到目前爲止,我所有的努力來證明文本,導致同樣的行爲。我試過通過內聯樣式的CSS int eh html文本,或者使用textAlignment
屬性。
問題是,證明文字可以打破字母間距(實際上它會增加每個單詞的跟蹤/字距,而不是僅增加兩者之間的空格)。
請參見:
我想看到這樣一個解決方案,是不是黑客攻擊,因爲我設計我自己的一些黑客後來我陷入了其他問題太多的可能性。
我是否想念一些簡單的東西?我已經通過了所有的UI選項,並且在我的代碼示例中看到,我甚至嘗試更改Kern,該Kern確實發生了變化,但只是按比例(即仍然增加)。
優秀!通過'paragraphStyle.hyphenationFactor = 1'或通過UI輕鬆實現。 – ericosg
這可能不是我正在尋找的直接答案,但它看起來非常好,我將使用它。如果我沒有得到可以保留文字並鎖定文本跟蹤的答案,我會將其標記爲已回答。 – ericosg
在我的解決方案中實現,但如果有人仍然想回答,我想知道如何保持自動換行+字距/跟蹤鎖定時。 – ericosg