objective-c iOS 7.0.3 上的“HelveticaNeue-Italic”发生了什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19527962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 21:08:09  来源:igfitidea点击:

What happened to "HelveticaNeue-Italic" on iOS 7.0.3

objective-cios7uifont

提问by Scott Sarnikowski

Just upgraded my iPod touch to iOS 7.0.3 and "HelveticaNeue-Italic" seems to have disappeared. When I query on the phone with:

刚刚将我的 iPod touch 升级到 iOS 7.0.3,“HelveticaNeue-Italic”似乎消失了。当我在电话上查询时:

[UIFont fontNamesForFamilyName:@"Helvetica Neue"]

I get the following fontNames (13):

我得到以下字体名称(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

When I do the same query running in the simulator I get (14):

当我在模拟器中运行相同的查询时,我得到 (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

Anyone else see this?

还有人看到这个吗?

---- New Information ----

- - 新讯息 - -

I went back to the WWDC 2013 video "Using Font with Text Kit" and the interesting part starts at 12:22. The presenter talks about "MetaFonts" in OS X as an example. What he says is that the font under calls like:

我回到了 WWDC 2013 视频“Using Font with Text Kit”,有趣的部分从 12:22 开始。演示者以 OS X 中的“MetaFonts”为例。他说的是,调用下的字体如下:

+ (NSFont *)messageFontOfSize:(CGFloat)fontSize

are not guaranteed to return the same underlying font across versions or even different uses. His example was Lucinda Grande. He did not seem to be saying that using "HelveticaNeue-Italic" could go away from version to version.

不保证跨版本甚至不同用途返回相同的底层字体。他的例子是露辛达格兰德。他似乎并没有说使用“HelveticaNeue-Italic”会因版本而异。

So I constructed an experiment in iOS 7. I created my font with the following code:

所以我在 iOS 7 中构建了一个实验。我使用以下代码创建了我的字体:

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

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

I did get a valid UIFont back for fontWithDescriptor and when I queried the font for the fontName with:

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

[fontWithDescriptor fontName]

I got back...

我回来了...

HelveticaNeue-Italic

Go figure???

去搞清楚???

So a possible answer to 7.0.3 seems to be the code above.

所以 7.0.3 的可能答案似乎是上面的代码。

---- Further Tweak ----

---- 进一步调整 ----

Although the solution worked above, I don't think it is formally correct. I have switched to the following solution

尽管上面的解决方案有效,但我认为它在形式上并不正确。我已切换到以下解决方案

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

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

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

This appears to do all the right things. I tried the previous approach with another font family and it seemed to get confused with a the fontName and the fontFamily. Hope this helps!

这似乎做了所有正确的事情。我用另一个字体系列尝试了以前的方法,它似乎与 fontName 和 fontFamily 混淆。希望这可以帮助!

回答by Mike Vosseller

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:

这是苹果的错误。它是在 iOS 7.0.3 中引入的,但在 iOS 7.0.4 中尚未修复。它似乎在 iOS 7.1 的开发者预览版中得到修复。以下是解决此问题的代码(由 Apple 在开发论坛中提供):

#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.

还值得注意的是,在当前版本的 Xcode (5.0.1 (5A2053)) 中,此字体未在 Interface Builder 的 Font 下拉列表中列为选项。因此,如果您之前使用这种字体配置了一个标签,您会注意到 ui 被混淆了,并且该标签最终在运行时被分配了一些其他字体和大小(请参阅下面的 ui 屏幕截图)。对于在 storyboards/xibs 中配置的标签,您需要在代码中重置字体。

For reference hereis the discussion of the issue in the dev forums.

作为参考,这里是开发论坛中对该问题的讨论。

enter image description here

在此处输入图片说明

回答by Dave DeLong

This is a bug in iOS 7.0.3.

这是 iOS 7.0.3 中的一个错误。

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

如果您明确使用 HelveticaNeue-Italic,则可以使用以下解决方法创建它:

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

Note, however, that this workaround will onlywork on iOS 7; it is not deployable to iOS 6 (because CTFontRefand UIFontwere not toll-free bridged on iOS 6). However, on iOS 6 you can just use your regular font lookup code.

但是请注意,此解决方法适用于 iOS 7;它不能部署到 iOS 6(因为CTFontRef并且UIFont不是在 iOS 6 上免费桥接)。但是,在 iOS 6 上,您可以只使用常规字体查找代码。

回答by David Lari

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.

我相信这是一个错误。我已将其提交给 Apple。对我来说可悲的是,我的应用程序现在崩溃了。该字体用于我正在使用的第 3 方库中。Twitter 上的许多人都在报告问题。

回答by Kapil Chandel

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.

如果您正在动态访问斜体字体,那么不是按名称访问字体,而是 [UIFont fontWithName:@"HelveticaNeue-Italic" size:15.0f]使用[UIFont italicSystemFontOfSize:15.0f]这对我来说很好。

回答by Michael Ochs

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!

我目前没有找到该会话,但他们说了一些您不能再依赖 iOS7 上可用字体的内容。它们甚至可以在您的应用程序的生命周期内发生变化。这基本上意味着:当你在你的应用程序中指定字体时,你被搞砸了,改用字体描述符或首选字体!

回答by Fateh Khalsa

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

我找到了另一个似乎有效的解决方案。我注销了一个电话

[[UIFont italicSystemFontOfSize:12.0] fontName]

[[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

查看实际使用的系统斜体字体是什么,它返回“.HelveticaNeueInterface-ItalicM3”。一个简单的测试表明,使用

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

[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.

作品!从视觉上比较它们,上述调用返回的字体似乎与原始的“HelveticaNeue-Italic”字体完全相同。

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...

这个问题几乎可以肯定是一个错误...... Helvetica Neue 是 iOS 7 中的默认字体,因此该系列中的字体不应丢失。在 Xcode v.5.0 中一切正常,但在升级到 5.0.1 后立即开始出现此问题。我已经向 Apple 提交了一个错误,并指出了这一点。在那之前,这个解决方案似乎有效......

回答by David Lari

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.

我向 Apple 提交的错误报告已标记为“已关闭为重复”。我希望这意味着他们确实认为这是一个错误。但是,iOS 7.0.4 并未修复该错误。

回答by Leo Natan

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

该错误似乎已在 iOS 7.1 beta 1 中修复。[UIFont fontWithName:@"HelveticaNeue-Italic" size:size];返回字体。

回答by Suresh Durishetti

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.

我有一个相同的崩溃,它曾经只在 iOS 7.0.3 和 7.0.4 中崩溃,并且在所有其他版本中完美运行。经过如此多的调查,我开始知道@"HelveticaNeue-Italic" 在 iOS 7.0.3 和 7.0.4 版本中不可用,所以我曾经在这些版本中遇到过崩溃问题。

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 

回答by Brian Rak

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

由于没有人提到 UIWebView 中的 HelveticaNeue 斜体支持,我想我会分享我的发现。

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.

从 7.0.6 开始,UIWebView 中仍然缺少常规斜体,并且似乎回退到同一系列中的 UltraLightItalic。当它紧挨着常规粗细的非斜体 HelveticaNeue 文本时,这看起来有点奇怪,因为它轻得多。

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

我的解决方法是使用普通 Helvetica 而不是 HelveticaNeue,但仅用于斜体。因此,如果您的 CSS 如下所示:

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

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

...您将添加另外两个类来覆盖<i><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.

常规的 Helvetica 斜体字体看起来不错,我认为没有人会注意到它不是 HelveticaNeue。