Reputation: 6109
Following the tutorial at here. I am adding a custom font by copying the font to the project and also adding it to the file Info.plist. I also double check and see that the font is also added in "Copy bundle resource" in 'Build Phase'.
However, when I am trying to print the name of the font by following
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.myLabel.text = @"This is a custom font";
self.myLabel.font = [UIFont fontWithName:@"Montserrat-Bold" size:36];
NSLog(@"my font is %@",[UIFont fontNamesForFamilyName:@"Montserrat-Bold"]);
}
and I am getting
2013-02-15 22:20:36.014 UsingCustomFont[5064:11303] my font is (
)
Please look at the image for what I have done.
Please help if you know what I am missing in the middle. Thanks
Upvotes: 2
Views: 1328
Reputation: 5384
try this
self.myLabel.text = @"This is a custom font";
self.myLabel.font = [UIFont fontWithName:@"Montserrat-Bold" size:36];
NSLog(@"my font is %@", myLabel.font.fontName);
Upvotes: 0
Reputation: 5384
Try looking at all of the available fonts:
for(NSString* family in [UIFont familyNames])
{
NSLog(@"%@", family);
for(NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@" %@", name);
}
}
Upvotes: 0
Reputation: 17186
First of all print all the fonts by below way:
// get font family
NSArray *fontFamilyNames = [UIFont familyNames];
for (NSString *familyName in fontFamilyNames)
{
// font names under family
for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
{
NSLog(@"Font Name = %@", fontName);
}
}
Now, take the exact name of font which is listed by above code. Sometimes the names differed by iOS.
While assigning the font, you should use font name and not the name of the family.
Upvotes: 3
Reputation: 62676
Another common gotcha is that the font file was added to the project but not to the target. Select the font file in the organizer and check it's target membership in the "Identity and Type" inspector on the right. Make sure that your target is checked.
Upvotes: 0
Reputation: 5200
A couple of issues I've run into in the past:
The font file may contain data in a format iOS does not support. In my experience, bitmap fonts don't work at all; only vector fonts are loaded.
You may be using the wrong family name. Check the array returned by [UIFont familyNames]
to make sure.
Upvotes: 3