0

我使用attributed strings在標籤上改變字母之間的間距「網絡連接」的信件:爲兩組字母IOS NSMutableAttributedString NSKernAttributeName錯字距與「FL」和

var attributedString=NSMutableAttributedString(string: "Fifi floflo") 
attributedString.addAttribute(NSKernAttributeName, value: CGFloat(10), range: NSRange(location: 0, length: attributedString.length)) 
label.attributedText=attributedString 

的字距運作良好節選其中是「FL」和「網絡」(也許別人沒看到目前)。 我使用「艾文莉介質」字體,但我基本的Arial字體測試,問題仍然存在。

With the word 'Profile'

With the word "Fifi floflo'

回答

2

NSAttributedStrings配備了默認啓用連字。連字將突出的字符組合結合成單個字形。如果您申請字母間距,你會希望將其禁用 - 否則這些信對字形不會分離。

attributedString.addAttribute(NSLigatureAttributeName, 
    value:0, 
    range: NSRange(location: 0, length: attributedString.length)) 

從文檔:

NSLigatureAttributeName

該屬性的值是包含一個整數一個NSNumber對象。連字會導致特定的字符的組合,以使用對應於這些字符單個自定義字形呈現。值0表示沒有連字。值1表示使用默認連字。值2表示使用所有連字。此屬性的默認值是1(值2是iOS上不支持。)

+0

我剛剛發現來自確實是文檔的解決方案。 –