我正在尝试为UILabel
显示的(NSLigatureAttributeName
)启用连字NSAttributedString
。
我的目标是iOS 6.1并在iPad模拟器中运行。
我的测试词是:
我的test code很简单,它循环显示单词列表,并使用UILabel
属性在text
中显示一个:
self.normalLabel.text = words[i];
另一个使用attributedText
属性,在创建NSAttributedString
之后(有关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)
答案 0 :(得分:3)
根据文档,iOS上不支持NSLigatureAttributeName 2.
NSLigatureAttributeName 该属性的值是NSNumber 包含整数的对象。连字导致特定的字符 要使用单个自定义字形呈现的组合 对应那些字符。值0表示没有连字。 值1表示使用默认连字。价值2 表示使用所有连字。这个的默认值 属性为1.(请注意,iOS上不支持值2.)可用 在iOS 6.0及更高版本中。
答案 1 :(得分:1)
这可能无法帮助您解决大部分测试单词的问题,但NSLigatureAttributeName的文档说明了这些问题:
English text has no essential ligatures, and typically has only two standard ligatures,
those for “fi” and “fl”—all others being considered more advanced or fancy.
根据这些信息,我对coffins
没有看到任何差异感到惊讶。
答案 2 :(得分:0)
使用Hoefler Text
附带iOS 6 does not support ligatures的Helvetica Neue解决了这个问题。