UIFont Woes(一些自定义字体加载,但其他的不是) [英] UIFont Woes (some custom fonts loading, but other's are not)

查看:190
本文介绍了UIFont Woes(一些自定义字体加载,但其他的不是)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,要加载某些自定义字体。我遵循了传统的,400 + upvoted答案的建议,并为一个项目完美的工作。然而,在我正在处理的另一个项目中,我遇到了加载UIFont的问题。



这些问题有点类似于在添加多个字体到UIAppFonts覆盖对方。那里的解决方案是有问题的p列表正确地解析出名字到XML导致覆盖。我试图测试这个问题的假设:
$ b $ p我在p-list中列出了字体在

UIAppFonts(变成应用程序提供的字体)
项目0 - Merriweather-Regular.ttf
项目1 - OpenSans-Regular.ttf
项目2 - OpenSans-Bold.ttf



最后一个(OpenSans-Bold)是唯一加载的。自那以后,我尝试了将这些物品移到无效的地方。我甚至从p-list和这个项目中删除了OpenSans-Bold.ttf,并试图运行它。显然他们不是相互覆盖。所有的文件被复制到我的捆绑副本(另一个常见的错误),仍然是唯一的文件注册OpenSans-Bold在我的任何意见。我已经删除了一切,并将其添加回来...基本上完成了所有传统的奇怪的XCode可能导致问题错误测试,它并没有改变任何东西。任何人有任何想法可能是什么问题?



非常感谢!

解决方案

答案是字体文件名称与字体名称不同。如果文件名称与OpenSans-Regular类似,则在调用fontWithName:时,您有时只需要使用OpenSans字体名称。这就是为什么OpenSans-Regular不起作用(因为它不是字体名称),而OpenSans-Bold却这样做(因为名称和文件一样)。

I'm having an issue getting certain custom fonts to load. I followed the advice in the traditional, 400+ upvoted answer to this question, and it worked for one project perfectly. However, in a different project I am working on I have run into issues with loading a UIFont.

These issues are somewhat similar to the issues found in the post Adding multiple fonts to UIAppFonts overrides each other. The solution there was that there were issues with the p-list properly parsing out the names into XML leading to overwriting. I have attempted to test that hypothesis of the issue:

I listed the fonts in my p-list under

UIAppFonts (which turns into "Fonts provided by application") Item 0 - Merriweather-Regular.ttf Item 1 - OpenSans-Regular.ttf Item 2 - OpenSans-Bold.ttf

The last of which (OpenSans-Bold) was the only one that loaded. I have since tried moving the items around to no effect. I have even deleted OpenSans-Bold.ttf from the p-list and the project and tried running it. Clearly then they are not "overwriting each other." All of the files were copied into my bundle copy (another common error) and still, the only file that registered was OpenSans-Bold in any of my views. I've deleted everything and added it back in... basically done all traditional "weird XCode could cause the problem" bug testing and it hasn't changed anything. Anyone have any idea what the issue could be?

Thanks a lot!

解决方案

The answer to this is that the font file name differs from the font name. If the file name is something like OpenSans-Regular, you sometimes only need to do the font name OpenSans when calling fontWithName:. This is why "OpenSans-Regular" did not work (as it was not the font name), whereas "OpenSans-Bold" did (since the name was the same as the file.)

这篇关于UIFont Woes(一些自定义字体加载,但其他的不是)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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