带字体手提箱的iPhone自定义字体 [英] iPhone Custom Fonts with Font Suitcase

查看:116
本文介绍了带字体手提箱的iPhone自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在iOS4应用程序中使用字体手提箱作为自定义字体,但没有取得任何成功。

I am attempting to use a Font Suitcase for a custom font in an iOS4 app but am not having any success.

我已阅读其他帖子,记录了如何使用自定义字体,因此将行李箱复制到我的项目中,将其添加到资源和应用程序阵列提供的Info.plist'
字体,并尝试在Interface Builder和代码中使用它。但它不起作用!

I have read other posts that have documented how to use custom fonts, so have copied the suitcase into my project, added it to resources and the Info.plist ' Fonts provided by application' array, and attempted to use it both in Interface Builder and in code. But it doesn't work!

我发现的有关自定义字体的所有示例都显示使用ttf或otf文件,但没有任何手提箱。可以吗?如果没有,我如何从Font Book中获取可用作自定义字体的文件结构?

All examples I've found regarding custom fonts show using them with ttf or otf files, but nothing with a suitcase. Can it be done? If not, how do I get something out of the Font Book into a file structure that can be used as a custom font?

推荐答案

我有同样的问题,只是解决了它。朋友给了我一些压缩的字体,我解压缩然后文件大小为零kb我无法将它们安装到Font Book中。
所以我用Google搜索,发现我的朋友应该使用StuffIt Expander来拉链。所以他又把文件发给我了,我用StuffIt Expander解压缩了。然后我就可以将字体安装到我的字体书中。

I had the same problem and just solved it. Friend gave me a couple of fonts zipped, I unzipped and then the file sizes are zero kb and I couldn't install them into Font Book. So I googled and found out that my friend should have used StuffIt Expander to zip. So he sent me the file again, and I used StuffIt Expander to unzip. I was then able to install the fonts into my Font Book.

然而,这些字体在我的iOS应用程序中仍然无法使用。以下是我的所作所为:

However, the fonts are still not usable in my iOS app. So below is what I did:


  1. 我发现我需要转换字体,所以我安装了Fondu
    http://fondu.sourceforge.net/
    安装结果说不成功,但后来我仍然可以使用。

  1. I found out I need to convert the font, so I installed Fondu http://fondu.sourceforge.net/ The installation ended up saying not successful, but later I was still able to use.

然后我意识到我需要Rosetta来运行Fondu,所以我查看了本页的说明。
拿出我的Snow Leopard CD并安装可选套件
http:// www.macobserver.com/tmo/article/snow_leopard_installing_rosetta/

Then I realise I need Rosetta to run Fondu, so I looked at the instructions on this page. Got my Snow Leopard CD out and install optional package http://www.macobserver.com/tmo/article/snow_leopard_installing_rosetta/

打开终端并转到您的字体所在的目录。输入命令:
fondu [font file]
然后你会得到一个提示,询问你是否要保存[font file] .pfb
选择是。

Open Terminal and go to the directory where your font is. Type the command: fondu [font file] Then you will get a prompt asking if you want to save [font file].pfb Choose yes.

现在在您的XCode中,将pfb文件添加到项目中。然后转到info.plist并将文件添加到UIAppFonts(包括.pfb扩展名)。

Now in your XCode, add the pfb file into your project. Then go to info.plist and add the file to UIAppFonts (include the .pfb extension).

我测试了UITableViewCell中的字体

I tested the font in a UITableViewCell

cell.textLabel.font = [UIFont fontWithName:@[font file]size:30]; //不包括.pfb扩展名

cell.textLabel.font = [UIFont fontWithName:@"[font file]" size:30]; // do not include .pfb extension

字体显示正常。我最初认为iOS将需要一个.ttf文件,但看起来像.pfb也没关系。

And the font is showing up fine. I initially thought iOS will require a .ttf file but looks like .pfb is fine also.

希望这会有所帮助。

其他测试提示:
如上所示添加UIAppFonts plist数组后,在appDidFinishLaunchingWithOptions方法和控制台类型中添加断点

Additional testing tips: Once you add the UIAppFonts plist array as shown above add a breakpoint in your appDidFinishLaunchingWithOptions method and at the console type

po [UIFont familyNames]

这样可以获得已安装字体的列表搜索您的字体系列名称。复制并粘贴到此:

That gets you a list of installed fonts so search for your font family name. Copy that and paste it into this:

po [UIFont fontNamesForFamilyName:@"familyname"]

这将获取您在代码中引用的字体名称。我没有尝试[font filename]方法,但这会为您提供应用程序用来引用您想要的确切字体的名称。当字体包含一系列变体或您从同一系列安装了多个变体时,这一点很重要。例如,helvetica有四种变体,因此您可以这样选择正确的变体:

This gets you the font name you reference in your code. I've not tried the [font filename] approach but this gives you the name the app uses to reference the exact font you want. This is important when a font contains a series of variants or you have multiple installed from the same family. For example helvetica has four variants so you can pick the right one this way:

lblMyLabel.font = [UIFont fontWithName:@"fontname" size:lblMyLabel.font.pointSize]

例如

lblMyLabel.font = [UIFont fontWithName:@"Helvetica-Oblique" size:lblMyLabel.font.pointSize]

这样可以保留最初用于标签的字体磅值。加载视图后,我也只取得了成功。

This keeps the font point size you used originally for the label. I've also only had success once the view is loaded.

这篇关于带字体手提箱的iPhone自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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