Adding custom font (Impact) to iOS project not working

This is a topic that looks like many others have fought. I am trying to add an Impact font to my iOS project. To do this, I do the following:
1. Add the Impact.ttf file to your project.
2. Make sure the Impact.ttf file is actually added to the Target project.
3. Check "Copy the asset package" to the target build phases and make sure the Impact.ttf file is included.
4. In My-Project-Name-Info.plist I added the option "Fonts provided by the application" and set Impact.ttf as element 0 in the array.
5. Open the font file with Font Book and make sure I reference the font with the correct name. In this case, Impact is the correct name.

I have used the following code cut to view 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 checking the UIFont value in the following snippet, I get zero.

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

      

I did four times checking all the spellings and went through each step several times. I've also used the following resources (and many more) to troubleshoot this issue.

One element to note: If I open Impact.ttf with a font book, it says the font is not installed. I click to install a font and I get a warning about duplicate Impact fonts. To fix this warning, I automatically click Allow Duplicates and the font appears as installed. However, if I open the file again, the font appears as not installed.

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

Many thanks for your help! I know this question has been asked several times, but I feel like I have exhausted all the resources and links here on SO and other sites.

+3


source to share


1 answer


This may not be the answer you want, but it is a solution you can use to continue. This is what I use in my projects, simple and useful https://github.com/deni2s/IBCustomFonts



Hope you can find a better solution!

+2


source







All Articles