Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding custom fonts to iOS app finding their real names

I have two fonts to add in my app for using.

Here is the font images. Currently the files are named as

name.font       = [UIFont fontWithName:@"Helvetica Neue LT Pro-Medium" size:10]; headline.font   = [UIFont fontWithName:@"Helvetica Neue LT Pro-Light" size:8]; 

putting same name in the Font Avaliable option in plist file.

I have also tried adding file names like

HelveticaNeueLTPro-Lt HelveticaNeueLTPro-Md 

but nothing seems to work. How can i get the exact name of the fonts.

enter image description here

like image 276
Muhammad Umar Avatar asked Apr 13 '13 06:04

Muhammad Umar


People also ask

How do I put custom fonts on my iPhone apps?

You can download fonts from the App Store app , then use them in documents you create on iPhone. After you download an app containing fonts from the App Store, open the app to install the fonts. To manage installed fonts, go to Settings > General, then tap Fonts.

How use OTF font in iOS?

Add the Font File to Your Xcode Project To add a font file to your Xcode project, select File > Add Files to “Your Project Name” from the menu bar, or drag the file from Finder and drop it into your Xcode project. You can add True Type Font (. ttf) and Open Type Font (. otf) files.


Video Answer


1 Answers

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:

func dumpAllFonts() {     for familyName in UIFont.familyNames {         for fontName in UIFont.fontNames(forFamilyName: familyName) {             print(fontName)         }     } } 
like image 195
rob mayoff Avatar answered Sep 30 '22 19:09

rob mayoff