Reputation: 764
I found a strange behaviour of NSAttributedString in iOS 7 with system font when using "ff" string. It's counted as single letter. Here is result and code to test.
Is it bug or feature? How can I get rid of this without changing font?
If I change font to anything else letters are colored correctly.
@property (nonatomic) IBOutlet UILabel *testText
- (void)testALetter
{
NSDictionary *blackText = @{NSForegroundColorAttributeName : [UIColor blackColor],
NSFontAttributeName : [UIFont systemFontOfSize:48]};
NSDictionary *orangeText = @{NSForegroundColorAttributeName : [UIColor orangeColor],
NSFontAttributeName : [UIFont systemFontOfSize:48]};
NSRange range = NSMakeRange(2, 1);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"aaaaaa" attributes:blackText];
[attributedString setAttributes:orangeText range:range];
[self.testText setAttributedText:attributedString];
}
- (void)testFLetter
{
NSDictionary *blackText = @{NSForegroundColorAttributeName : [UIColor blackColor],
NSFontAttributeName : [UIFont systemFontOfSize:48]};
NSDictionary *orangeText = @{NSForegroundColorAttributeName : [UIColor orangeColor],
NSFontAttributeName : [UIFont systemFontOfSize:48]};
NSRange range = NSMakeRange(2, 1);
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"ffffff" attributes:blackText];
[attributedString setAttributes:orangeText range:range];
[self.testText setAttributedText:attributedString];
}
Upvotes: 2
Views: 320