使用 iPhone 上没有的字体
我想使用一些不属于 iPhone 操作系统的字体。 我见过使用非标准字体的游戏。 我可以安装字体,在 Photoshop 中为每种字体创建图像,然后在 iPhone 应用程序中使用这些图像。 但是,我认为这不是一个实用的方法。 如果需要调整颜色或色调(由于背景)或大小,我将不得不重新设计我正在使用的每种字体。 有一个更好的方法吗?
我读过这篇 我可以在 iPhone 中嵌入自定义字体吗应用程序?并下载了开源字体标签应用程序。 然而,当我尝试使用特定字体时,它大多数时候都会崩溃。 关于使用 UIFont 和 fontWithName:size 的最后评论,这当然行不通。 你的字体变量将为零。 列出所有可用字体可以揭示原因 - 列表中没有任何自定义字体。
我还阅读了 如何包含字体我的 iPhone 应用程序?,这肯定不起作用。 与上面链接中的最后评论相同。
I'd like to use some fonts that aren't part of the iPhone OS. I've seen games that use non standard fonts. I can install the fonts, create images for each one in Photoshop and then use those images in the iPhone app. However, I don't think that is a practical way to go. If the color or tint needs to be adjusted (because of background) or size, I'll have to redesign every font I'm using. Is there a better way to do this?
I read this Can I embed a custom font in an iPhone application? and downloaded the open source font label app. However, it crashes most of the time when I try using particular fonts. In regards to the last comment about using UIFont with the fontWithName:size, that certainly doesn't work. Your font variable will be nil. Listing all available fonts reveals why - none of the custom fonts are in the list.
I've also read How do I include a font with my iPhone application?, which definitely does not work. Same as last comment in above link.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
正确的答案是使用 FontLabel,可以在 GitHub 上找到它。 http://github.com/zynga/FontLabel
我已经在几个现实世界中使用过该代码项目,这绝对是太棒了。
更新:
自 iOS 3.2(仅限 iPad)起 iPhone 上的 iOS 4 中,您可以将 TTF 字体打包到您的应用程序包中。 使用 UIAppFonts 键将它们输入 Info.plist 后。
这里的三步说明:
http://kgriff.posterous.com/45359635
The correct answer is to use FontLabel, which can be found on GitHub. http://github.com/zynga/FontLabel
I've used that code in several real-world project and it's absolutely fantastic.
UPDATE:
As of iOS 3.2 (iPad only) & iOS 4 on the iPhone, you can package TTF fonts within your app bundle. After entering them into your Info.plist using the UIAppFonts key.
Three step instructions here:
http://kgriff.posterous.com/45359635
解决方案是将新属性“应用程序提供的字体”添加到您的 info.plist 文件中。
然后,您可以像普通 UIFont 一样使用自定义字体。
The solution is to add a new property "Fonts provided by application" to your info.plist file.
Then, you can use your custom font like normal UIFont.
这实际上很容易。
您将 ttf 包含在应用程序包中。 您将
Fontsprovided by application
/UIAppFonts
键添加到您的应用程序中,这是您所包含的字体(包括扩展名)的文件名数组,例如:您可以使用
UIFont
轻松使用字体:这适用于所有 iOS从 3.2 开始的版本,包括从 iOS 4 开始的 iPhone。
This is actually quite easy.
You include your ttf in the app bundle. You add the
Fonts provided by application
/UIAppFonts
key to your application, this is an array of file names for fonts you are including (including the extension) e.g.:You can the use the font quite easily using
UIFont
:This works on all iOS versions from 3.2, including on the iPhone from iOS 4.
遗憾的是,这并不是一个立即的答案,但似乎在未来,您将能够将自定义字体作为您的应用程序的一部分:
不幸的是,这仅适用于 iPhone OS 3.2,这是 iPad 特定版本。 该功能似乎很可能会在未来的 iPhone 操作系统版本中提供。
链接: http://developer.apple.com/iPhone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW18
(这是我在苹果网站上能找到的唯一公开文档)
This sadly is not an immediate answer, but it seems that in the future, you will be able to include custom fonts as part of your app:
Unfortunately, this works only in iPhone OS 3.2, which is the iPad specific version. It does seem very likely that this feature will be available in future iPhone OS releases.
Link: http://developer.apple.com/iPhone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW18
(this was the only public documentation I could find on Apple's site)