IOS7.0.3上的“ HelveticaNeue-Italic”发生了什么

刚刚把我的 iPod touch 升级到 iOS7.0.3,“ HelveticaNeue-Italic”似乎消失了。当我打电话询问:

[UIFont fontNamesForFamilyName:@"Helvetica Neue"]

我得到以下 fontNames (13) :

HelveticaNeue-BoldItalic,
HelveticaNeue-Light,
HelveticaNeue-UltraLightItalic,
HelveticaNeue-CondensedBold,
HelveticaNeue-MediumItalic,
HelveticaNeue-Thin,
HelveticaNeue-Medium,
HelveticaNeue-ThinItalic,
HelveticaNeue-LightItalic,
HelveticaNeue-UltraLight,
HelveticaNeue-Bold,
HelveticaNeue,
HelveticaNeue-CondensedBlack

当我在模拟器中运行相同的查询时,我得到(14) :

HelveticaNeue-BoldItalic,
HelveticaNeue-Light,
**HelveticaNeue-Italic,**
HelveticaNeue-UltraLightItalic,
HelveticaNeue-CondensedBold,
HelveticaNeue-MediumItalic,
HelveticaNeue-Thin,
HelveticaNeue-Medium,
HelveticaNeue-Thin_Italic,
HelveticaNeue-LightItalic,
HelveticaNeue-UltraLight,
HelveticaNeue-Bold,
HelveticaNeue,
HelveticaNeue-CondensedBlack

有人看到这个吗?

——新信息——

我回到 WWDC 2013视频“使用字体与文本工具包”,有趣的部分在12:22开始。演讲者以 OSX 中的“ MetaFonts”为例。他说的是调用下面的字体是这样的:

+ (NSFont *)messageFontOfSize:(CGFloat)fontSize

不能保证在不同版本甚至不同用法中返回相同的底层字体。他的榜样是 Lucinda Grande。他似乎并没有说使用“ HelveticaNeue-斜体”可以从一个版本到另一个版本。

所以我在 iOS7中做了一个实验,我用下面的代码创建了我的字体:

UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:@"Helvetica Neue" size:16.0];
UIFontDescriptor *symbolicFontDescriptor = [fontDescriptor fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];


UIFont *fontWithDescriptor = [UIFont fontWithDescriptor:symbolicFontDescriptor size:16.0];

我的确为 fontWithDescriptor 获得了一个有效的 UIFont,当我用以下方法查询 fontName 的字体时:

[fontWithDescriptor fontName]

我回来了。

HelveticaNeue-Italic

你猜怎么着?

因此,7.0.3的一个可能的答案似乎就是上面的代码。

——进一步调整——

虽然上面的解决方案起作用了,但我不认为它在形式上是正确的

    UIFontDescriptor *fontDescriptor = [[UIFontDescriptor alloc] init];


UIFontDescriptor *fontDescriptorForHelveticaNeue = [fontDescriptor fontDescriptorWithFamily:@"Helvetica Neue"];
UIFontDescriptor *symbolicFontDescriptor = [fontDescriptorForHelveticaNeue fontDescriptorWithSymbolicTraits:UIFontDescriptorTraitItalic];


textFont = [UIFont fontWithDescriptor:symbolicFontDescriptor size:textFontPointSize];

这看起来做了所有正确的事情。我用另一个字体家族尝试了前面的方法,但它似乎与 fontName 和 fontFamily 混淆了。希望这个能帮上忙!

27973 次浏览

I currently don't find the session but they said something that you can not rely on fonts being available anymore on iOS7. They can even change during the lifetime of your app. Which basically means: When you specify fonts in your app, you are screwed, use font descriptors or preferred fonts instead!

It is my belief that it is a bug. I have filed it as such with Apple. Sadly for me, my app is now crashing. The font is used in a 3rd party library I am using. Many folks on Twitter are reporting problems.

This is an Apple bug. It was introduced in iOS 7.0.3 and has not yet been fixed as of iOS 7.0.4. It appears to be fixed in the developer preview of iOS 7.1. Here is code (provided by Apple in the dev forums) to workaround the issue:

#import <CoreText/CoreText.h>


CGFloat size = 14;
UIFont *font = [UIFont fontWithName:@"HelveticaNeue-Italic" size:size];
if (font == nil && ([UIFontDescriptor class] != nil)) {
font = (__bridge_transfer UIFont*)CTFontCreateWithName(CFSTR("HelveticaNeue-Italic"), size, NULL);
}

It is also worth noting that in the current version of Xcode (5.0.1 (5A2053)) this font is not listed as an option in the Font drop down list in Interface Builder. So if you previously configured a label with this font you will notice that the ui is confused and the label ends up being assigned some other font and size at runtime (see ui screencap below). For labels configured in storyboards/xibs you will need to reset the font in code.

For reference here is the discussion of the issue in the dev forums.

enter image description here

I've found another solution that seems to work. I logged out a call to

[[UIFont italicSystemFontOfSize:12.0] fontName]

to see what the actual system italic font being used is, and it returned ".HelveticaNeueInterface-ItalicM3". A simple test shows that using

[UIFont fontWithName:@".HelveticaNeueInterface-ItalicM3" size:12.0]

works! Comparing them visually, the font returned by the above call appears to be exactly the same as the original 'HelveticaNeue-Italic' font.

This problem is almost certainly a bug... Helvetica Neue is the default font in iOS 7, so fonts in that family shouldn't be missing. Everything worked fine in Xcode v.5.0, but immediately after upgrading to 5.0.1, this issue started appearing. I've filed a bug with Apple noting as much. Until then, this solution seems to work...

This is a bug in iOS 7.0.3.

If you are explicitly using HelveticaNeue-Italic, then you can create it using this workaround:

UIFont* font = (__bridge_transfer UIFont*)CTFontCreateWithName(CFSTR("HelveticaNeue-Italic"), fontSize, NULL);

Note, however, that this workaround will only work on iOS 7; it is not deployable to iOS 6 (because CTFontRef and UIFont were not toll-free bridged on iOS 6). However, on iOS 6 you can just use your regular font lookup code.

If you are dynamically accessing the italic font then instead of accessing the font by name [UIFont fontWithName:@"HelveticaNeue-Italic" size:15.0f] use [UIFont italicSystemFontOfSize:15.0f] this is working fine for me.

The bug report I filed with Apple has been marked "Closed as duplicate". I am hopeful that means they do consider it a bug. However, iOS 7.0.4 does not fix the bug.

The bug seems to have been fixed in iOS 7.1 beta 1. [UIFont fontWithName:@"HelveticaNeue-Italic" size:size]; returns a font.

Since no one has mentioned anything about HelveticaNeue italic support in UIWebView, I thought I'd share my findings.

As of 7.0.6, the regular italic is still missing in UIWebView and appears to fall back to UltraLightItalic in the same family. This looks a little weird when it's right next to regular weight non-italic HelveticaNeue text since it is so much lighter.

My workaround was to use ordinary Helvetica instead of HelveticaNeue, but only for the italics. So if you have CSS that looks like this:

.myCssClass {
font-family:HelveticaNeue;
/* etc, etc */
}

...you would add two other classes to override <i> and <em>:

.myCssClass i  { font-family:Helvetica; }
.myCssClass em { font-family:Helvetica; }

The regular Helvetica italic font looks fine and I don't think anyone would notice that it's not HelveticaNeue.

I had a same crash which used be to crash in iOS 7.0.3 & 7.0.4 only, and works perfectly in all other versions. After so much investigation, I came to know that @"HelveticaNeue-Italic" is not available in iOS 7.0.3 & 7.0.4 versions, so that I used to get above crash in those versions.

I have fixed the issue with below code, this might helpful to someone needy.

self.headerFont = [UIFont fontWithName:@"HelveticaNeue-Italic" size:16.0f];
if (self.headerFont == nil) {
self.headerFont = [UIFont fontWithName:@"HelveticaNeue" size:16.0f];
}

The crash log is:

[__NSCFConstantString pointSize]: unrecognized selector sent to instance