Question

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!

Was it helpful?

Solution

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top