连接在iOS 6中的UILabel / NSAttributedString中不起作用

时间:2013-05-02 11:03:49

标签: cocoa ios6 uilabel nsattributedstring

我正在尝试为UILabel显示的(NSLigatureAttributeName)启用连字NSAttributedString

我的目标是iOS 6.1并在iPad模拟器中运行。

我的测试词是:

  • aeciospore
  • 乳糜泻
  • halfheaded
  • cliffhanging
  • aufkommender
  • snuffkin
  • domineesbriefjes
  • offtrack
  • dahinraffte
  • 棺材

我的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)。但这对单词没有影响:

Ligatures do not working in UILabel using Attributed Strings

Ligatures do not working in UILabel using Attributed Strings

我正在使用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) 

3 个答案:

答案 0 :(得分:3)

根据文档,iOS上不支持NSLigatureAttributeName 2.

  

NSLigatureAttributeName   该属性的值是NSNumber   包含整数的对象。连字导致特定的字符   要使用单个自定义字形呈现的组合   对应那些字符。值0表示没有连字。   值1表示使用默认连字。价值2   表示使用所有连字。这个的默认值   属性为1.(请注意,iOS上不支持值2.)可用   在iOS 6.0及更高版本中。

http://developer.apple.com/library/ios/#documentation/uikit/reference/NSAttributedString_UIKit_Additions/Reference/Reference.html

答案 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解决了这个问题。