Adding Custom Fonts To IOS App Finding Their Real Names


Answer :

Use +[UIFont familyNames] to list all of the font family names known to the system. For each family name, you can then use +[UIFont fontNamesForFamilyName:] to list all of the font names known to the system. Try printing those out to see what name the system expects. Example code:

static void dumpAllFonts() {     for (NSString *familyName in [UIFont familyNames]) {         for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {             NSLog(@"%@", fontName);         }     } } 

Put that in your app, call it, and see what you get. If you see a name in the output that looks appropriate for your font, use it. Otherwise, perhaps you haven't properly added the font to your app.

In swift 4.2+ use code given below:

func dumpAllFonts() {         for familyName in UIFont.familyNames {             for fontName in UIFont.fontNames(forFamilyName: familyName) {                 print("\(fontName)")             }         }     } 

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.

Also read This and This tutorials for improve your knowledge.

FOR MOREINFORMATION :

But after adding font to your application, sometimes might be the font name is not the name of the file name so you need to apply/write real name of your font, so check @NSGod's answer.

Following is code for find all fonts from the system:

for(NSString *fontfamilyname in [UIFont familyNames]) {     NSLog(@"Family:'%@'",fontfamilyname);     for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname])     {         NSLog(@"\tfont:'%@'",fontName);     }     NSLog(@"~~~~~~~~"); } 

Might be above step and suggestion is helpful in your case:


While it appears that UIFont's fontNamed:size: method is fairly forgiving with the names you provide, the official fontName has always been the font's internal PostScript name. A font's PostScript name cannot contain spaces and usually has them replaced by a hyphen. I don't recall offhand, but I believe they may also be limited to 31 characters.

Determining what name you should use in code is extremely simple. Double click on the font you want to use on your iOS device to open it in Font Book. If the font is not already installed, click the Install button in the sample window that appears. When it's installed, select the font in the Font list. In Font Book's menu, choose Preview > Show Font Info. That will show info about the font like shown in the image below:

enter image description here

As you can see, the PostScript name for Helvetica Neue LT Std 65 Medium is HelveticaNeueLTStd-Md. That's the name you should use in code.

In your Info.plist file, under fonts for the application, you need to use the actual filename of the font itself, whatever that happens to be. In my case, it was HelveticaNeueLTStd-Md.otf.


Comments

Popular posts from this blog

Are Regular VACUUM ANALYZE Still Recommended Under 9.1?

Can Feynman Diagrams Be Used To Represent Any Perturbation Theory?