How to enable and use new fonts in iPhone SDK?

I want to use the MgOpen Modata font in my iphone application. But I do not see it in the font list in the Property inspector.

How to enable this font so that I can use it?

+53
objective-c iphone cocoa-touch ios4
Feb 11 2018-11-11T00:
source share
8 answers
  • Add font files to your resource files
  • Edit your Info.plist : add a new entry using the Fonts provided by application key.
  • For each of your files, add the file name to this array

In the example below, I added the font "DejaVu Sans Mono":

Info.plist: adding custom fonts

In your application, you can use [UIFont fontWithName:@"DejaVuSansMono-Bold" size:14.f] .

Or, if you want to use it in html / css, just use font-family:DejaVu Sans Mono;

Note. it is available in iOS version 3.2 and later.

+135
Feb 11 2018-11-11T00:
source share

I found this walkthrough was the best

Although the above answer does work, I found that if you added text to the XIB file, and then set the font to our new font, the text will not update.

After making sure that the new font is included in the resources, this problem has been fixed (taken directly from the walkthrough):

"This should not be a problem, but sometimes when you have problems displaying the face of the font, it can be a source of headache, so now let's double-check it as a potential trap.

Go to the "Phase Assembly" panel of the project, highlighting the Xcode project file in your solution browser and on the right, select "Generate Phases". You will see that one of the sections that you can expand is Copy Bundle Resources. Open this list and make sure your fonts are included in this list.

Make sure the fonts are included in our resources

Other things in the walkthrough are the same stuff (add the file to your project and to the plist file too)

All the credit for the code with Chris for this answer, which saved me a lot of time and effort, and I just copy the snapshot from his page so that this answer can stand on its own feet, and not require you to click the link.

+13
Oct 12 '14 at 23:53
source share

Do not forget to add fonts to objects compiling package resources by going to "Goals" β†’ "Generate phases" β†’ "Copy package resources" and add all fonts manually

+6
Dec 18 '14 at 12:24
source share

I think it is better for the developer to have a plist structure as the source code. I leave it to copy / paste:

 <key>UIAppFonts</key> <array> <string>Roboto-BoldItalic.ttf</string> <string>Roboto-Medium.ttf</string> <string>Roboto-MediumItalic.ttf</string> <string>Roboto-Regular.ttf</string> <string>Roboto-Bold.ttf</string> </array> 

Copy this snippet and change the lines in the array to the desired fonts. Tip . To view plist as source code, click the secondary button above the file and select Open As β†’ Source Code .

EDIT

 // Logs fonts ordered by name for (NSString* family in [[UIFont familyNames] sortedArrayUsingSelector:@selector(compare:)]) { NSLog(@"%@", family); for (NSString* name in [[UIFont fontNamesForFamilyName:family] sortedArrayUsingSelector:@selector(compare:)]) { NSLog(@" %@", name); } } 

After adding fonts, it can be useful to add (for example) the AppDelegate.m class to see what the names of the real fonts are (on the set). The problem that I encountered at different times was that I downloaded fonts with the wrong name, assuming the font file name is correct. Sometimes it differs from the real name of the bundle. In addition to this, you can check the full file name using the file info window (cmd + i) on finder (macOS).

Example for clarification:
File Name = "DroidSansEthiopic-Regular"
Processed name in bundle = "Droid Sans Ethiopic"

+6
Oct 22 '15 at 21:26
source share

In most cases, we forget to add the font to the Target application. Make sure you have not forgotten this important step. Verify that the Control Panel File Inspector> Target Membership is correct.

enter image description here

You can also verify that the wether font has been added to your application or not by running this piece of code anywhere in your application.

 for (NSString* family in [UIFont familyNames]) { NSLog(@"%@", family); for (NSString* name in [UIFont fontNamesForFamilyName: family]) { NSLog(@" %@", name); } } 

EDIT

ALPHABETE ORDER:

 for (NSString* family in [[UIFont familyNames] sortedArrayUsingSelector:@selector(compare:)]) { NSLog(@"%@", family); for (NSString* name in [[UIFont fontNamesForFamilyName:family] sortedArrayUsingSelector:@selector(compare:)]) { NSLog(@" %@", name); } } 

This will populate the list of available fonts in your application, where your added font will also appear.

+4
Nov 25 '14 at 7:53
source share

In Xamarin iOS

Step 1: First of all, you should add your .ttf or .otf to your project.

like Roboto-BoldItalic.ttf .

Step 2: Right-click on the font and select the property

  • Assembly action β†’ Contents
  • Copy to output directory β†’ Always copy

Step 3: go to info.plist

select the Fonts provided by application property and add a font name.

enter image description here

Step 4:

install font programmatically below

 account.Font = UIFont.FromName("Roboto-BoldItalic", 18f); 
+1
Mar 18 '17 at 6:34
source share

You can directly use the [UIFont fontWithName:@"ArialMT" size:14]; method [UIFont fontWithName:@"ArialMT" size:14]; if you want to change the font style. Also, all fonts may not be available in the iphone library. Just specify this for the available font styles.

0
Feb 11 '11 at 13:15
source share

If you have a .otf format. once this format does not work. Convert .otf format to .ttf. There are many font converters online. After adding a custom font to the .plist file in the "Fonts" section provided by the application, as described above. Make sure your project target is in the β€œBuild Phase” section β†’ copy Bundel Resourse that the file is present. If not, add it. Then only in your code add this [UIFont fontWithName: @] your own font "size: your choice of size";

0
Mar 05 '14 at 17:06
source share



All Articles