ios - "The fi bug"奇怪的 iOS 7 属性文本错误

标签 ios iphone objective-c ios7


我在 iOS 7 中遇到了一个奇怪的错误,我称之为“fi 错误”。

摘要:
“fi”这两个字符被视为一个字符。

解释:
我创建了一个带有单词的 UILabel,作为属性文本。 我创建了一个函数,在单击时将单词的一个字符着色为蓝色。 (即首先单击它为第一个字符着色, 第二次单击它会从第一个颜色到第二个颜色……)。

用iOS 6模拟器完全没有问题,当我们切换到iOS 7模拟器时,只要单词不包含“fi”就可以了。例如,当我写“金融”时,从第一次点击开始,f 和 i 都是蓝色的。

它不依赖于 'fi' 的位置,似乎只有 'fi' 有问题。

代码:

UILabel:
@property(强,非原子)IBOutlet UILabel *wordLabel;

着色函数:

- (void) changeWordLabelWithWord:( NSString *)word to:(int) position{
NSMutableAttributedString *coloredText = [[NSMutableAttributedString alloc] initWithString:word];

[coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:0.25 green:0.66 blue:0.96 alpha:1] range:NSMakeRange(0,position)];

_wordLabel.attributedText = coloredText;
}

感谢您的帮助和见解^^。
干杯!

最佳答案

您可以在 NSMutableAttributedString 上将“ligature”属性设置为零。 来自 documentation :

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. (Value 2 is unsupported on iOS.)

使用默认值 1,字母“fi”呈现为一个字形。 一些字体甚至具有三个字符序列的连字,例如“ffl”。

关于ios - "The fi bug"奇怪的 iOS 7 属性文本错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21369439/

相关文章:

ios - 获取控件的纵向和横向原始框架

ios - UIPageControl 点不可见但框架可见

iphone - 如何实现AdBannerview和ADBannerview委托(delegate)

iphone - 使用带有 ARC 的 ios5 选择地址簿地址

ios - 通过 TestFlight 安装 iOS 应用是否模拟应用升级?

objective-c - Nested NSDictionary 的访问对象

ios - Xcode 断点在 dispatch_async block 内不起作用

ios - APN后台刷新,设置AppDelegate.m

ios - 如何知道哪个对象发送了通知

objective-c - 自定义 NSBox 的 UI 问题