如何在iPhone应用程序中包含字体?

时间:2023-01-13 13:00:05

I've already seen this post:

我已经看过这篇文章:

Can I embed a custom font in an iPhone application?

我可以在iPhone应用程序中嵌入自定义字体吗?

which is helpful, but I'd love to simply load the font via:

这很有帮助,但我很乐意通过以下方式加载字体:

UIFont* font = [UIFont fontWithName:@"Harrowprint" size:20];

Some people have reported this possible but it's not working for me. Can someone confirm how to bundle a custom font with an iphone app?

有些人报告说这可能,但它不适合我。有人可以确认如何将自定义字体与iphone应用程序捆绑在一起吗?

Also, in the aforementioned post, one answer notes: The "name" of the font is not necessarily the filename.

另外,在上述帖子中,一个答案注意到:字体的“名称”不一定是文件名。

How do I determine the "name" of the font that would be recognized by UIFont? It's possible i'm not using the correct name.

如何确定UIFont可识别的字体的“名称”?我可能没有使用正确的名称。

2 个解决方案

#1


13  

There are several steps you need to take:

您需要采取以下几个步骤:

1) Make sure you have the rights to distribute the font. Most fonts -- even free ones -- do not allow you to distribute them. Putting them in your app most likely consitutes 'distribution' and would be considered illegal.

1)确保您有权分发字体。大多数字体 - 甚至是免费字体 - 都不允许您分发它们。将它们放入您的应用程序最有可能构成“分发”,并被视为非法。

2) Copy the font to your Resources folder in your app. Make sure it's in your Copy Files build phase.

2)将字体复制到应用程序中的Resources文件夹。确保它位于“复制文件”构建阶段。

3) Add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension)

3)在plist文件中添加“应用程序提供的字体”键,并添加字体的完整文件名(包括扩展名)

4) Get the 'name' of the font by putting in a temporary line of code:

4)通过放入一行临时代码获取字体的“名称”:

NSLog(@"%@",[UIFont familyNames]);

Build and run the app. This will print to the Console the family names of all the fonts on the device. Find the one that matches your font.

构建并运行应用程序。这将在控制台上打印设备上所有字体的系列名称。找到与您的字体匹配的那个。

You can then use that font name in the fontWithName: method.

然后,您可以在fontWithName:方法中使用该字体名称。

#2


5  

To add onto August's answer above, you need to add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension). Then the font will appear in the family printout and you can use that name to set the font.

要添加到上面八月的答案,您需要在plist文件中添加“由应用程序提供的字体”键,并添加字体的完整文件名(包括扩展名)。然后字体将出现在族打印输出中,您可以使用该名称来设置字体。

#1


13  

There are several steps you need to take:

您需要采取以下几个步骤:

1) Make sure you have the rights to distribute the font. Most fonts -- even free ones -- do not allow you to distribute them. Putting them in your app most likely consitutes 'distribution' and would be considered illegal.

1)确保您有权分发字体。大多数字体 - 甚至是免费字体 - 都不允许您分发它们。将它们放入您的应用程序最有可能构成“分发”,并被视为非法。

2) Copy the font to your Resources folder in your app. Make sure it's in your Copy Files build phase.

2)将字体复制到应用程序中的Resources文件夹。确保它位于“复制文件”构建阶段。

3) Add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension)

3)在plist文件中添加“应用程序提供的字体”键,并添加字体的完整文件名(包括扩展名)

4) Get the 'name' of the font by putting in a temporary line of code:

4)通过放入一行临时代码获取字体的“名称”:

NSLog(@"%@",[UIFont familyNames]);

Build and run the app. This will print to the Console the family names of all the fonts on the device. Find the one that matches your font.

构建并运行应用程序。这将在控制台上打印设备上所有字体的系列名称。找到与您的字体匹配的那个。

You can then use that font name in the fontWithName: method.

然后,您可以在fontWithName:方法中使用该字体名称。

#2


5  

To add onto August's answer above, you need to add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension). Then the font will appear in the family printout and you can use that name to set the font.

要添加到上面八月的答案,您需要在plist文件中添加“由应用程序提供的字体”键,并添加字体的完整文件名(包括扩展名)。然后字体将出现在族打印输出中,您可以使用该名称来设置字体。