Rashad.Z
Rashad.Z

Reputation: 2604

Custom Font in IOS Not Reflected On Device

i followed this tutorial and the custom font was shown on my storyboard but when i executed my app (on simulator or device) the font is not reflected. can anyone help. this is what i did:

1- downloaded a .ttf file and copied it to my project
2- added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font.
3- opened storyboard and selected the UILabel i want to have a custom font for, and selected the font as custom then selected my font. the font was shown on the storyboard correctly.

am i missing something?

Upvotes: 4

Views: 1530

Answers (3)

Rashad.Z
Rashad.Z

Reputation: 2604

Thank you @Andrey Chernuka and @jcaron. I solved the problem by setting the target membership to my project and then exiting the project (cleaning did not work for some reason) and reopening the project and everything was set. the font name was appearing when i printed print (UIFont.familyNames())

Upvotes: 5

Nimit Parekh
Nimit Parekh

Reputation: 16864

You just follow below steps.

Step 1 - downloaded a .ttf file and copied it to my project Step 2 - added "Fonts Provided By Application" in info.plist and added a row having the name of my custom font.

enter image description here

Step 3 - Display added fonts exist into project or not. copy past into application:didFinishLaunchingWithOptions

NSLog(@"Available fonts: %@", [UIFont familyNames]);
NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
    NSArray *fontNames;
    NSInteger indFamily, indFont;
    for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
    {
        NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
        fontNames = [[NSArray alloc] initWithArray:
                     [UIFont fontNamesForFamilyName:
                      [familyNames objectAtIndex:indFamily]]];
        for (indFont=0; indFont<[fontNames count]; ++indFont)
        {
            NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
        }

    }

Step 4 - find the name of your font and same name check into story board.

It's definitely works.

Upvotes: 1

Uma Madhavi
Uma Madhavi

Reputation: 4917

Have you added .ttf folder to supporting files only. Then Edit info.Plist like this

Fonts provided by Application take as array

Item 0 as Heiti SC.ttf

now you can set label.font = [UIFont fontWithName:@"Heiti SC" size:15];

Then you also need to add ttf file to copy bundle resources in target build phases.

Upvotes: 1

Related Questions