-[UILabel setFont:] 中断言失败

发布于 2024-12-07 06:05:34 字数 359 浏览 0 评论 0原文

我在 iOS 3.1.2 中设置 UILabel 字体时遇到此异常,但在 iOS 4 中运行良好,

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'

代码行是,

Outbound_Label.font = [UIFont fontWithName:@"DS-Digital" size:24];

其中 DS-Digital 是我的自定义字体。

I am getting this exception on setting a font of UILabel in iOS 3.1.2 but its running fine in iOS 4,

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: font != nil'

The code line is,

Outbound_Label.font = [UIFont fontWithName:@"DS-Digital" size:24];

where DS-Digital is my custom font.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

年少掌心 2024-12-14 06:05:34

[UIFont fontWithName:@"DS-Digital" size:24] 返回 nil。因为“DS-Digital”没有可用的字体(Apple 支持的字体列表)。所以它导致了崩溃。

[UIFont fontWithName:@"DS-Digital" size:24] returns nil. Because no font available for "DS-Digital" (Apple supported font list). so it giving the crash.

同尘 2024-12-14 06:05:34

我的猜测是您的自定义字体没有被实例化。

每当我遇到这样的问题,其中发生两件事:获取字体和设置字体时,我会将它们分开以查找问题:

UIFont *font = [UIFont fontWithName:@"DS-Digital" size:24];
Outbound_Label.font = font;

然后我可以使用调试器或 NSLog() 轻松确定错误在哪里。

事实上,这是一种非常清晰的编写代码的方式。我从不担心优化,我只担心清晰度和易于维护。稍后,如果我分析出性能问题,找到真正的罪魁祸首并解决它们。代码越清晰就越容易。

在这种情况下,编译器无疑会优化掉字体变量,因此没有任何害处。

请参阅:所以答案

想要使用自定义字体的应用程序现在可以将这些字体包含在其应用程序包中,并通过在 Info.plist 文件中包含 UIAppFonts 键来向系统注册这些字体。该键的值是一个字符串数组,用于标识应用程序包中的字体文件。当系统看到该密钥时,它会加载指定的字体并使它们可供应用程序使用。

My guess is that your custom font is not being found instantiated.

Whenever I have a problem like this where there are two things happening: obtaining a font and setting a font, I separate them to find the problem:

UIFont *font = [UIFont fontWithName:@"DS-Digital" size:24];
Outbound_Label.font = font;

Then I can determine where the error is easily with either the debugger or NSLog().

In fact this is a very clear way to write the code in the first place. I never worry about optimization, I only worry about clarity and ease of maintenance. Later if there are performance issues I profile, find the real culprits and resolve them. The clearer the code the easier that is.

In a case like this the compiler will undoubtedly optimize away the font variable so there is no harm.

See this:SO answer

Applications that want to use custom fonts can now include those fonts in their application bundle and register those fonts with the system by including the UIAppFonts key in their Info.plist file. The value of this key is an array of strings identifying the font files in the application’s bundle. When the system sees the key, it loads the specified fonts and makes them available to the application.

寂寞美少年 2024-12-14 06:05:34

请尝试一下这个,它对我来说效果很好。

https://github.com/zynga/FontLabel

我已经从 http://www.fontriver.com/font/ds-digital/
并使用此字体运行上述应用程序,它适用于 IOS 3.1.2。

干杯。

Please try this, it's works fine for me.

https://github.com/zynga/FontLabel

i have download DS-Digital font from http://www.fontriver.com/font/ds-digital/
and run the above app with this font and it's works with IOS 3.1.2.

Cheers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文