“错误的错误”一个奇怪的iOS 7归因于文本错误 [英] "The fi bug" A weird iOS 7 attributed text bug

查看:89
本文介绍了“错误的错误”一个奇怪的iOS 7归因于文本错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


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

I'm having a weird bug in iOS 7, I've called it "the fi bug".

摘要:

两个字符fi被视为一个字符。

Abstract:
The two characters "fi" are considered as one character.

说明:

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

Explanation:
I have created an UILabel with a word in it, as an attributed text. I created a function that on click colors one character of the word in blue. (i.e. first click it colors the first character, second click it colors from the first to the second…).

使用iOS 6模拟器没有任何问题,当我们切换到iOS 7模拟器时,只要单词上不包含fi,一切都很好。例如,当我写金融时,从第一次点击开始,f和i都用蓝色着色。

With iOS 6 simulator no problem at all, when we switch to iOS 7 simulator, everything is okey as long as the word does not contain "fi" on it. For instance when I write "finance", from the first click both f and i are colored in blue.

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

It does not depend on the 'fi' position, and seems to have the problem only with 'fi'.

代码:

UILabel:

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

The UILabel:
@property (strong, nonatomic) 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;
}

感谢您的帮助和见解^^。

干杯!

Thank you for your help and insight ^^.
Cheers !

推荐答案

您可以在<$ c上将ligature属性设置为零$ C> NSMutableAttributedString 。
来自
文档


NSLigatureAttributeName

此属性的值为NSNumber
包含整数的对象。 Ligatures导致特定字符
组合使用单个自定义字形呈现,
对应于这些字符。值0表示没有连字。
值1表示使用默认连字。值2
表示使用所有连字。此
属性的默认值为1.(iOS上不支持值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. (Value 2 is unsupported on iOS.)

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

With the default value 1, the letters "fi" are rendered as one glyph. Some fonts even have ligatures for three character sequences such as "ffl".

这篇关于“错误的错误”一个奇怪的iOS 7归因于文本错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆