我可以在 iPhone 应用程序中嵌入自定义字体吗? [英] Can I embed a custom font in an iPhone application?

查看:33
本文介绍了我可以在 iPhone 应用程序中嵌入自定义字体吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个应用程序包含用于呈现文本的自定义字体,加载它,然后将它与标准的 UIKit 元素一起使用,例如 UILabel.这可能吗?

I would like to have an app include a custom font for rendering text, load it, and then use it with standard UIKit elements like UILabel. Is this possible?

推荐答案

iOS 3.2 及更高版本支持此功能.直接来自 iPhone OS 3.2 中的新功能 文档:

iOS 3.2 and later support this. Straight from the What's New in iPhone OS 3.2 doc:

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

Custom Font Support
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.

Info.plist 中设置字体后,您可以在 IB 或以编程方式将自定义字体用作任何其他字体.

Once the fonts have been set in the Info.plist, you can use your custom fonts as any other font in IB or programatically.

Apple 开发者论坛上有一个正在进行的主题:
https://devforums.apple.com/thread/37824(需要登录)

There is an ongoing thread on Apple Developer Forums:
https://devforums.apple.com/thread/37824 (login required)

这是一个关于如何实现这一目标的优秀而简单的 3 步教程(已删除断开的链接)

And here's an excellent and simple 3 steps tutorial on how to achieve this (broken link removed)

  1. 使用 Xcode 作为资源将您的自定义字体文件添加到您的项目中
  2. 向您的 Info.plist 文件添加一个名为 UIAppFonts 的密钥.
  3. 将此键设为数组
  4. 对于您拥有的每种字体,输入字体文件的全名(包括扩展名)作为 UIAppFonts 数组的项目
  5. 保存Info.plist
  6. 现在在您的应用程序中,您只需调用 [UIFont fontWithName:@"CustomFontName" size:12] 来获取自定义字体以与您的 UILabels 一起使用>UITextViews 等……
  1. Add your custom font files into your project using Xcode as a resource
  2. Add a key to your Info.plist file called UIAppFonts.
  3. Make this key an array
  4. For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array
  5. Save Info.plist
  6. Now in your application you can simply call [UIFont fontWithName:@"CustomFontName" size:12] to get the custom font to use with your UILabels and UITextViews, etc…

另外:确保字体在您的复制包资源中.

Also: Make sure the fonts are in your Copy Bundle Resources.

这篇关于我可以在 iPhone 应用程序中嵌入自定义字体吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆