在iOS应用程序中安装特定字体时遇到问题 - 不兼容的TTF? [英] Having trouble installing specific font in an iOS app - incompatible TTF?

查看:270
本文介绍了在iOS应用程序中安装特定字体时遇到问题 - 不兼容的TTF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码库中有一些字体文件,用于字体Nubian和Nubian-Alt。他们被许可和支付,他们需要使用。但是,我不能在iOS中使用这种字体,即使字体在Finder中预览OK,并且被标识为Truetype字体,也无法用Font Book打开字体。

< img src =https://i.stack.imgur.com/tflEC.pngalt =Finder查看bad字体>

I通过尝试将Nubian-Medium添加到iOS应用程序开始 - 使用应用程序的Info.plist中的应用程序提供的字体键。字体没有出现在生成的列表中:

  for(NSString * familyName in [UIFont familyNames]){
(NSString * fontName in [UIFont fontNamesForFamilyName:familyName]){
NSLog(@%@,fontName);






我检查了Target的Copy Bundle Resources构建阶段,看到字体已被添加到列表中。

我尝试添加另一个字体,我在另一个应用程序chess-merida-unicode.ttf中使用,以检查我正在添加一个正确的字体 - 我将它复制到应用程序,并将其添加到由应用程序提供的字体数组,看到它出现在复制束资源列表中,它被报告为可用使用上面的代码片段。 p>

接下来我看了一下OS X中的字体 - 双击打开字体书,但字体没有打开或添加。当我尝试将所有Nubian字体拖放到Font Book中时,它会报告所有文件的问题,特别是在字体文件中包含的表格中。





选择所有字体,然后选择继续,什么都不做。

我下载了名为Font Agent Pro的第三方应用程序的试用版,也无法加载这些字体。我发现一个名为fonts.com的粗略网站,并下载了另一个Nubian-Medium(ufonts.com_nubian-medium_1_.ttf) - Xcode能够识别该文件。



我检查了这些文件的权限,确保它们是rw,没有任何变化。这一点你会怀疑这些文件只是破损或损坏,但他们正在使用的网页(这也是项目的一部分),并且工作正常。我可以采取哪些其他步骤?我能做些什么来将这些文件添加到iOS项目中?如果在某个iOS项目中有某些类型的TTF不能使用,那我该如何检查它们是否属于这种类型?解析方案

>答案似乎是这些字体是网络字体的。我不知道如何区分,给定一个TTF文件,看起来就像一个桌面字体。学习如何做到这一点是这个问题的目的。

实际上,从某人的硬盘中挖出一个旧的存档,发现另一个存有TTF字体的存档。这些字体仍然有8.3文件名,并且都被创建为他们自己的字体系列的成员(所以Nubian-Medium和Nubian-MediumItalic没有任何关系)。我重命名了他们,然后通过RoboFonts的试用来纠正家庭关系。这导致所有在努比亚家庭TTF。然后发现一个奇怪的问题,用这个字体创建的UILabel在框架的顶部有一个1像素的水平线。再次通过这个过程,但选择产生OTF输出摆脱了线。



字体很容易,除非没有,那么他们真的很难。 / p>

There are some font files in my code repo for the font Nubian and Nubian-Alt. They are licensed and paid for and they need to be used. However I cannot use this font in iOS, and I cannot open the font with Font Book even though the font previews OK in Finder and is identified as a Truetype Font.

I started by trying to add Nubian-Medium to the iOS app - using the key "Fonts provided by application" in the app's Info.plist. The font did not appear in the list generated using:

 for (NSString *familyName in [UIFont familyNames]) {
   for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
     NSLog(@"%@", fontName);
   }
 }

I checked the Target's "Copy Bundle Resources" Build Phase, saw the font had been added to the list.

I tried adding another font I have used in another app, "chess-merida-unicode.ttf", to check I was adding a font correctly - I copied it to the app and added it to the array of fonts provided by application, saw it appear in the "Copy Bundle Resources" list, it was reported as available using the above code snippet.

Next I took a look at the font in OS X - double-clicking does open Font Book but the font is not opened or added. When I tried to drag all the Nubian fonts into Font Book as a new collection it reported problems with all the files, specifically in tables contained within the font file.

Selecting all fonts and then choosing proceed did nothing.

I downloaded a trial of a third-party app named Font Agent Pro and it also could not load these fonts.

I found a sketchy site called fonts.com and downloaded another Nubian-Medium ("ufonts.com_nubian-medium_1_.ttf") - Xcode was able to recognise that file.

I checked the permissions on these files and made sure they were rw for all, no change.

At this point you would suspect the files are just broken or corrupted but they are in use on a web page (that is also part of the project) and that works fine. What other steps could I take? What can I do to get these files added to the iOS project? If there are certain kinds of TTF that cannot be used in an iOS project, how can I check whether these are that kind?

解决方案

The answer seems to be that these fonts were "web" fonts. I don't know how to tell the difference, given a TTF file that looks just like a "desktop" font. Learning how to do this was kind of the aim of the question.

Practically speaking, digging out an old archive from someone's hard drive discovered another archive with TTF fonts that worked. These fonts still had 8.3 filenames and were all created as members of their own font family (so Nubian-Medium and Nubian-MediumItalic were in no way related). I renamed them, then ran them through the trial of RoboFonts to correct the family relationship. This resulted in TTFs all in the Nubian family. And then found a weird issue where a UILabel created with this font came with a 1-pixel horizontal rule at the top of the frame. Going through the process again but choosing to generate OTF output got rid of the line.

Fonts are easy, except when they aren't, then they are really hard.

这篇关于在iOS应用程序中安装特定字体时遇到问题 - 不兼容的TTF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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