Tulleb
Tulleb

Reputation: 9206

Add custom fonts with folder reference

Is it possible to add a custom font from a referenced folder (blue one)? My project structure Reference in my Info.plist PCH file
By doing this, my fonts are not recognized in the application. Did I miss something...? Thanks a lot!

EDIT: @Simon Degn: It doesn't work this way either.

I removed the path from Info.plist: My Info.plist without path reference

And from my PCH: PCH File

I have 6 exceptions rising without message when I launch my app: Exception

For your information I was previously with unreferenced folder (yellow one) and it was working nicely. I'd just like to switch to the referenced folder mode from now on. If that is possible.

Upvotes: 6

Views: 912

Answers (2)

jklp
jklp

Reputation: 2101

Not sure if it's too late to responsed but you're nearly there.

When specifying the font in the info.plist, you're correct in specifying it as the following (where Assets/Font/Averia_Sans_Libre is the folder reference prefix)

Assets/Font/Averia_Sans_Libre/*.ttf

When you load the app, if you run the following you can see if the font has been loaded:

NSLog(@"All fonts: %@", [UIFont familyNames].description);

Then to use the font, use the following with the FONT NAME, not the FONT FILE NAME (which is what you've done in your example above).

[UIFont fontWithName:@"Averia Sans Libre" size:@"15"];

You can find the name of the font using the example provided by Simon Degn (below)

Upvotes: 4

Simon Degn
Simon Degn

Reputation: 968

Yes - leave out the path. You only have to include the file name in the plist.

Run this to verify if the font is included:

NSArray *fontFamilies = [UIFont familyNames];

for (int i = 0; i < [fontFamilies count]; i++)
{
    NSString *fontFamily = [fontFamilies objectAtIndex:i];
    NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
    NSLog (@"%@: %@", fontFamily, fontNames);
}

and this will also reveal the name for the font, which will be used in the code, when you will use the font.

Upvotes: -1

Related Questions