0

I am trying to add multiple fonts to Xcode 6. The problem is when there are multiple styles of the same family for example:

"Mensch-Bold" "Mensch-Thin"

When I open these fonts I get the same name as the raw font file as shown below:

Mensch-Bold

Mensch-Thin

When I add these fonts, update the .pList file with the fonts etc, I can only get "Mensch" to work. I cannot get any of the sub families, and it's because they are all named the same "Mensch" despite their variations.

Is there a work around for this? Do you know how I can install multiple font styles of the same font family?

Aggressor
  • 13,323
  • 24
  • 103
  • 182

1 Answers1

0

Probably you have already installed both families. Xcode6 shows custom fonts in the Attributes tab however if you have more than 1 style from the same font family only one of them shows up. You can use subclasses to get this working.

First find the font names you have installed by using the following code: (Adding custom fonts to iOS app finding their real names)

static void dumpAllFonts() {
    for (NSString *familyName in [UIFont familyNames]) {
        for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
            NSLog(@"%@", fontName);
        }
    }
}

Then add a subclass, and use the font name that you got from the previous code. The following example is for UILabel.

@interface CustomFontLabel : UILabel

@end


@implementation CustomFontLabel

- (void)awakeFromNib {
    [super awakeFromNib];
    self.font = [UIFont fontWithName:@"Mensch" size:self.font.pointSize];
}

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.font = [UIFont fontWithName:@"Mensch" size:self.font.pointSize];
    }
    return self;
}

@end

After this you can change the class of the label to CustomFontLabel from the xib file.

Community
  • 1
  • 1
irmakoz
  • 1,166
  • 2
  • 12
  • 21