Search code examples
iosios6uitableviewuilabeluifont

How do I add a custom font to my app?


Edit: I figured it out! Answer is posted below. Thanks JSD!

I must be missing something because I thought this was a fairly simple process. I have already copied the font over to my project folder. I am trying to use the font in a UILabel on a Table Cell with this code:

UILabel *cellTitle = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 300, 40)];
cellTitle.font = [UIFont fontWithName:@"Source Sans Pro Black" size:50];
[cell.contentView addSubview:cellTitle];

It doesn't seem to be working. The text appears but not with the custom font. What am I missing?

EDIT: Apparently if I use this code instead

cellTitle.font = [UIFont fontWithName:@"Source Sans Pro" size:50];

This works but it's only using the last font in my array of my pList file, which is only the Regular version of the font. Has anyone ever had this issue before?

None of these codes work either:

cellTitle.font = [UIFont fontWithName:@"Source Sans Pro Bold" size:50];
cellTitle.font = [UIFont fontWithName:@"Source Sans Pro Regular" size:50];

This is the font in my font book:

enter image description here

PList file:

enter image description here


Solution

  • I just got it working!!! Thanks to JSD for steering me in the right direction. Apparently the issue is how XCode renames font variants that are in the same family.

    Using the Font Book name doesn't work!!!

    You actually have to see how Xcode names the fonts. In order to do that you have to run a log command:

    NSLog(@"%@", [UIFont fontNamesForFamilyName:@"Source Sans Pro"]);
    

    gave me this:

    enter image description here

    This code worked:

    cellTitle.font = [UIFont fontWithName:@"SourceSansPro-Black" size:50];