Why Does Kerning fail for NSAttributedString in IOS7

☆樱花仙子☆ 提交于 2019-12-19 04:39:07

问题


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

  1. When the below code is compiled on iPad running IOS6, the kern works as expected.
  2. When compiled on iPad running IOS7, no kerning occurs.

I have filed Bug at Apple Developer site. #15108371 - No Response 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:


OK. I had the same problem (see comment above). It depends on the font (I used Courier as well). For some strange reason Courier does not support kerning (in iOS7!). Use CourierNewPSMT and everything works as expected .... at least for me.

BTW: Here is a nice list of fonts on the iphone: http://iosfonts.com/



来源:https://stackoverflow.com/questions/19253442/why-does-kerning-fail-for-nsattributedstring-in-ios7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!