Why Kerning Fails at NSAttributedString in iOS7

My application has a UILabel formatted as NSAttributedString with the attribute: 'NSKernAttributeName @ 1.9,'

  • When the code below is compiled on an iPad running iOS6, the kernel works as expected.
  • When compiling on an iPad running iOS7, no kerning occurs.

I registered Bug on the Apple Developer website. # 15108371 - There is no answer yet

NSString *formattedNumber; NSNumber *scoreNum = [[NSNumber alloc] initWithLongLong:thisScore]; NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init]; formatter.numberStyle = NSNumberFormatterPadBeforeSuffix; formatter.formatWidth = 10; formatter.paddingCharacter = @"0"; formatter.numberStyle = NSNumberFormatterDecimalStyle; formatter.usesGroupingSeparator = NO; formattedNumber = [formatter stringFromNumber:scoreNum]; //Creat atributed string of formated number. NSShadow *textShadow = [[NSShadow alloc] init]; textShadow.shadowColor = [UIColor colorWithRed:0.5 green:0.7 blue:1 alpha:1.0]; textShadow.shadowBlurRadius = 5.0; textShadow.shadowOffset = CGSizeMake(0,0); NSAttributedString *pHighScoreStyle = [[NSAttributedString alloc] initWithString:formattedNumber attributes: @{ NSFontAttributeName: [UIFont fontWithName:@"courier" size:16], NSForegroundColorAttributeName: [UIColor colorWithRed:0.6 green:0.8 blue:1.0 alpha:0.8], NSKernAttributeName: @1.9, NSShadowAttributeName: textShadow } ]; //Change the disply value. runningScore.attributedText = pHighScoreStyle; 
+1
source share
1 answer

OK I had the same problem (see Comment above). It depends on the font (I also used Courier). For some strange reason, Courier doesn't support kerning (on iOS7!). Use CourierNewPSMT and everything works as expected .... at least for me.

By the way: Here is a good list of fonts on iphone: http://iosfonts.com/

+2
source

All Articles