如何在我的iPhone应用程序中包含字体? [英] How do I include a font with my iPhone application?

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

问题描述

我已经看过这则讯息:



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



'd爱通过简单的加载字体:

  UIFont * font = [UIFont fontWithName:@Harrowprintsize:20] ; 

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



此外,在上述文章中,一个答案说明:字体的名称不一定是文件名。



如何确定UIFont可以识别的字体的名称?

解决方案

您需要执行以下几个步骤:



1)确保您有权分发字体。大多数字体 - 甚至是免费的 - 不允许您分发它们。



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



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



4)通过输入临时代码行获取字体的'name':

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

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



然后可以在 fontWithName:方法中使用该字体名称。 / p>

I've already seen this post:

Can I embed a custom font in an iPhone application?

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?

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.

解决方案

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.

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

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

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

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.

这篇关于如何在我的iPhone应用程序中包含字体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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