2

plist file

included font

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.

CalZone
  • 1,701
  • 1
  • 17
  • 29

4 Answers4

4

Check Target membership of the font(.ttf) files.

user2443329
  • 118
  • 4
3

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]];
Dipen Panchasara
  • 13,480
  • 5
  • 47
  • 57
  • Thanks, Already tried that. And when I log `NSLog(@"%@",font1);` It gives null. It usually happens if my asset is not included in bundle. I just made sure it is there. The problem still persists. Do you think there might be something wrong with the font ? I copied it from fontbook only – CalZone Mar 24 '13 at 11:59
  • dear friend, i have downloaded Impact font from http://fontzone.net/font-download/impact and tested in my App its working. try to get a copy from this site. lets hope for positive. Good luck. – Dipen Panchasara Mar 24 '13 at 12:01
  • 1
    dont add extension of font. use only fontname "Impact" [UIFont fontWithName:@"Impact" size:12.0f]]; I dont think anything wrong other than this. – Dipen Panchasara Mar 24 '13 at 12:13
1

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);
   }
}
Community
  • 1
  • 1
thvanarkel
  • 1,601
  • 1
  • 12
  • 19
1

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.
iPatel
  • 46,010
  • 16
  • 115
  • 137