cocoa - iOS 6 中的 UILabel/NSAttributedString 中的连字不起作用

标签 cocoa ios6 uilabel nsattributedstring

我正在尝试打开连字 (NSLigatureAttributeName)对于 NSAttributedStringUILabel 显示。

我的目标是 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)。但这对文字没有影响:

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) 

最佳答案

根据文档,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.

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

关于cocoa - iOS 6 中的 UILabel/NSAttributedString 中的连字不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16336421/

相关文章:

cocoa - 使用 NSTask 创建 zip 存档,其中包含包含文件的第一级文件夹

objective-c - 来自@synthesize 的方法?

objective-c - UILabel 有最大高度吗?

swift - 如何将 UILabel 的文本保存在安全区域内?

macos - 我可以让复选框在发送其操作之前直观地更改其状态吗?

objective-c - CFReadStreamRef 始终为 nil

ios - 缩放后如何将 View 位置重置为原点

iphone - UIAlertView 导致 iOS SDK 6.0 崩溃

ios - CFBundleDocumentTypes 未注册

ios - 向 UILabel 添加左/右水平填充