【问题标题】:Why Does Kerning fail for NSAttributedString in IOS7为什么 IOS7 中 NSAttributedString 的字距调整失败
【发布时间】:2013-10-31 05:35:11
【问题描述】:

我的应用有一个格式化为 NSAttributedString 的 UILabel 属性:'NSKernAttributeName @1.9,'

  1. 在运行 IOS6 的 iPad 上编译以下代码时,kern 可以正常工作。
  2. 在运行 IOS7 的 iPad 上编译时,不会发生字距调整。

我已在 Apple Developer 网站上提交了 Bug。 #15108371 - 还没有回应

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;

【问题讨论】:

  • 我在 iOS6 中工作时遇到同样的问题,而在 iOS7 中不工作。我不像你那样使用 UILabel,而是使用低级 CoreText。你收到苹果的回音了吗?他们接受你的错误了吗?
  • Apple 还没有任何消息。
  • 如果有人需要解决方案,请在此处查看:stackoverflow.com/questions/20580736/…

标签: ios7


【解决方案1】:

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

顺便说一句:这是 iphone 上一个不错的字体列表: http://iosfonts.com/

【讨论】:

  • 谢谢你,内格。也感谢字体列表。苹果的艰难日子。
  • 是的,我切换到 New Courier 并发现字距调整按预期工作。提出有关字体标准的问题。 New Courier 是否符合更复杂的标准?
  • 不,我认为那只是 Apple 的一个错误
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-08-06
  • 1970-01-01
  • 2018-06-10
  • 1970-01-01
  • 1970-01-01
  • 2021-11-02
  • 1970-01-01
相关资源
最近更新 更多