我正在尝试打开连字 (NSLigatureAttributeName
)对于 NSAttributedString
由 UILabel
显示。
我的目标是 iOS 6.1 并在 iPad 模拟器中运行。
我的测试词集是:
- 空孢子
- 乳糜泻
- 半头半脑
- 悬崖峭壁
- aufkommender
- 鼻烟
- 多米内斯布里耶斯
- 偏离轨道
- dahinraffte
- 棺材
我的test code很简单,它循环遍历单词列表并使用 text
属性在 UILabel
中显示一个单词:
self.normalLabel.text = words[i];
另一个在创建 NSAttributedString
后使用 attributedText
属性(有关 NSLigatureAttributeName
值的更多信息,请参阅 Brandon Campbell's 答案) ):
NSDictionary *attrs = @{ NSFontAttributeName : [UIFont systemFontOfSize:74.0],
NSLigatureAttributeName : @1, //@2 not supported in iOS
NSBackgroundColorAttributeName : [UIColor redColor]};
self.attr.attributedText = [[NSAttributedString alloc] initWithString:words[i] attributes:attrs];
如您所见,我将 NSLigatureAttributeName
设置为 2(作为 NSNumber
)。但这对文字没有影响:
我使用的是systemFont
(Helvetica Neue),这是调试器输出:
(lldb) po self.attr.attributedText
$0 = 0x0719bc90 aeciospore{
NSBackgroundColor = "UIDeviceRGBColorSpace 1 0 0 1";
NSFont = "<UICFFont: 0x719cc80> font-family: \".Helvetica NeueUI\"; font-weight: normal; font-style: normal; font-size: 74px";
NSLigature = 1;
}
(lldb)
最佳答案
根据文档,iOS 不支持 NSLigatureAttributeName 2。
NSLigatureAttributeName The value of this attribute is an NSNumber object containing an integer. Ligatures cause specific character combinations to be rendered using a single custom glyph that corresponds to those characters. The value 0 indicates no ligatures. The value 1 indicates the use of the default ligatures. The value 2 indicates the use of all ligatures. The default value for this attribute is 1. (Note that value 2 is unsupported on iOS.) Available in iOS 6.0 and later.
关于cocoa - iOS 6 中的 UILabel/NSAttributedString 中的连字不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16336421/