1

Hi can someone give me a detail explanation on how to add custom font on iphone labels?

I have already created a key on info.plist

<key>UIAppFonts</key>
<array>
        <string>custom.ttf</string>
</array>

But don't know whats the next step.

1 Answers1

4

All custom font on iphone(development) should be added on app info.plist

Add row

<key>UIAppFonts</key>
<array>
        <string>custom.ttf</string>
</array>

Then add the custom.ttf to the project.

Create a subclass of the UILabel

@interface CustomLabel : UILabel {

}

@end

@implementation CustomLabel

- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super initWithCoder: decoder]) {
        UIColor *textColor = [UIColor colorWithRed:0.20f green:0.20f blue:0.20f alpha:1.0f];
        [self setTextColor:textColor];
        [self setShadowColor:textColor];
        [self setHighlightedTextColor:textColor];
        [self setFont:[UIFont fontWithName:@"custom" size:self.font.pointSize]];
    }
    return self;
}

@end

Thats it, you are ready for the custom font on your label.

Note:

For every labels you add on the app that you want to have a custom font, change the class identity to CustomLabel(name of the subclass UILabel).

DLende
  • 5,162
  • 1
  • 17
  • 25
  • I have similar kind of issue. I have used custom font. As normal font works fine but when there is special characters then font is not working.. Can you please help me – Mayur Oct 14 '15 at 17:56