Reputation:
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.
Upvotes: 1
Views: 1435
Reputation: 5242
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).
Upvotes: 4