mafellows
mafellows

Reputation: 178

Adding custom font (Impact) to iOS project not working

This is a topic that looks like many others have struggled with. I'm trying to add the 'Impact' font to my iOS project. To do so, I perform the following steps:
1. Add the Impact.ttf file to my project.
2. Ensure that the Impact.ttf file is in fact added to the project Target.
3. Check 'Copy Bundle with Resources' in the target Build Phases and make sure the Impact.ttf file is included .
4. In My-Project-Name-Info.plist, I added the "Fonts provided by application" option and set Impact.ttf as item 0 in the array.
5. Open the font file with Font Book and make sure I'm referencing the font by the correct name. In this case, Impact is the correct name.

I used the following code snipped to see all available fonts in the project, and 'Impact' is not one of them:

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

When inspecting the value of UIFont in the following snippet, I get nil.

UIFont *impactFont = [UIFont fontWithName:@"Impact" size:36.0f]; 

I've quadruple checked all spellings and gone through each step multiple times. I've also used the following resources (and many more) to troubleshoot the problem.

One item to note: If I open Impact.ttf with font book, it says that the font is not installed. I click to install the font, and get a warning that there are duplicate Impact fonts installed. To fix this warning, I click 'Resolve duplicates automatically' and the font shows as installed. However, if I open the file again, the font shows as not installed.

I'm not sure if having the font installed in Font Book is necessary for it to correctly be recognized in my project .

Thank you very much for your help! I know this question has been asked multiple times, but I feel like I've exhausted all resources and links here on SO and other sites.

Upvotes: 3

Views: 1447

Answers (1)

Sonia Casas
Sonia Casas

Reputation: 800

Maybe this is not the answer you want, but is a solution you could use to move on. That is what i use on my projects, simple and useful https://github.com/deni2s/IBCustomFonts

Hope you can find a better solution!

Upvotes: 2

Related Questions