Reputation: 1721
I'm trying to use Impact.ttf. It is in built in OSX, but can't see it in custom fonts on xcode. So I included it in my project as shown in screens and used
UIFont *font1 = [UIFont fontWithName:@"Impact.ttf" size:50];
NSLog(@"%@",font1);
self.labelTop.font = font1;
The Log is showing null value in font1. Plz help. How to include the font.
Upvotes: 2
Views: 2149
Reputation: 13600
First of all Add font .ttf file to Project then follow step
Step 1 : Click on ProjectName in Navigation Panel on Left Side
Step 2 : Go to Info Tab
Step 3 : Add New Key with name "Fonts provided by application" by Pressing "+" button
Step 4 : Set value for that key : Impact.ttf . its your font file name with extension
Step 5 : now you can use your custom font as follow
[textLabel setFont:[UIFont fontWithName:@"Impact" size:12.0f]];
Upvotes: 3
Reputation: 47099
This is Step for, How to add custom font in Application.
1 - Add .TTF
font in your application
2 - Modify the application-info.plist file
.
3 - Add the key "Fonts provided by application" to a new row
4 - and add each .TTF
file (of font) to each line.
For more info read This and This site.
FOR MOREINFORMATION :
For Bold
// Equivalent to [UIFont fontWithName:@"FontName-BoldMT" size:17]
UIFont* font = [UIFont fontWithFamilyName:@"FontName" traits:GSBoldFontMask size:17];
And bold/italic
UIFont* font = [UIFont fontWithMarkupDescription:@"font-family: FontName; font-size: 17px; font-weight: bold/italic;"]; // set here, either bold/italic.
Upvotes: 1
Reputation: 1611
As I said in this answer, the filename or the fontname might be different than the name that iOS likes to see in fontWithName:. Use Fontbook on your Mac to get the right name, if it still does not work after you have changed the filenames in the .plist. You can also enumerate through all fonts to find the right name by using the following code:
for(NSString *familyName in [UIFont familyNames]) {
for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(@"%@", fontName);
}
}
Upvotes: 1