添加了自定义字体在Xcode

添加了自定义字体在Xcode

本文介绍了添加了自定义字体在Xcode中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的应用中添加特定字体。我做了所有工作,比如将字体添加到资源,plist和Copy Bundle Resources。我甚至还添加了字体类,还搜索了很多内容。但一切都是徒劳的,没有什么对我有用。

I am trying to add a specific font in my app. I did all the work like adding the font to resources, to plist and to Copy Bundle Resources. I even added font classes as well and also googled a lot. But all in vain, nothing worked for me.

推荐答案

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

Custom Font SupportApplications 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开发者论坛上有一个持续的主题:
(需要登录)

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

这里有一个很棒的如何实现这一目标。

And here's an excellent tutorial on how to achieve this.

以下是转录的步骤:

使用XCode作为资源将自定义字体文件添加到项目中

Add your custom font files into your project using XCode as a resource

为您的信息添加密钥.plist文件名为UIAppFonts。

Add a key to your info.plist file called UIAppFonts.

将此键设为数组

对于您拥有的每种字体,请输入完整的字体文件的名称(包括扩展名)作为UIAppFonts数组的项目

For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array

保存info.plist

Save info.plist

现在在您的应用程序中,您只需调用[UIFont fontWithName:@CustomFontNamesize:12]即可获得与UILabels和UITextViews等一起使用的自定义字体...

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…

阿尔斯o:确保字体在Copy Bundle资源中。

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

复制自:

这篇关于添加了自定义字体在Xcode中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 08:28