为什么IOS7中的NSAttributedString的Kerning失败 [英] Why Does Kerning fail for NSAttributedString in IOS7

查看:132
本文介绍了为什么IOS7中的NSAttributedString的Kerning失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序将UILabel格式化为NSAttributedString,其中
属性为:'NSKernAttributeName @ 1.9,'

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


  1. 当下面的代码是在运行IOS6的iPad上编译的,kern按预期工作。

  2. 在运行IOS7的iPad上编译时,不会出现字距。

我已经在Apple Developer网站上提交了Bug。 #15108371 - 尚无回复

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;


推荐答案

好的。我遇到了同样的问题(见上面的评论)。这取决于字体(我也使用Courier)。由于一些奇怪的原因,Courier不支持字距调整(在iOS7中!)。 使用CourierNewPSMT,一切都按预期工作 ....至少对我而言。

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:这是一个很好的iphone字体列表:
http://iosfonts.com/

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

这篇关于为什么IOS7中的NSAttributedString的Kerning失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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