Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"The fi bug" A weird iOS 7 attributed text bug


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

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

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…).

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.

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

code:

The UILabel:
@property (strong, nonatomic) IBOutlet UILabel *wordLabel;

The coloring function:

- (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 !

like image 975
Dadadidadido Avatar asked Jan 26 '14 21:01

Dadadidadido


Video Answer


2 Answers

You can set the "ligature" attribute to zero on your NSMutableAttributedString. From the 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.)

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".

like image 59
Martin R Avatar answered Oct 03 '22 14:10

Martin R


iOS 7 adds a lot of typographical details. One of them are ligatures: the OS substitutes some character sequences by typographically better one glyph (character) variants.

like image 36
Nikolai Ruhe Avatar answered Oct 03 '22 15:10

Nikolai Ruhe