I want to use font \"MgOpen Modata\" in my iphone App. But I dont see it in the font list in Property inspector.
How do I include that font so that I can use it?
I want to use font \"MgOpen Modata\" in my iphone App. But I dont see it in the font list in Property inspector.
How do I include that font so that I can use it?
Info.plist
: Add a new entry with the key Fonts provided by application
.On the example below, I\'ve added the font \"DejaVu Sans Mono\":
In your application you can the 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: this is available in iOS 3.2 and later.
I found this walkthrough was the best
Although the above accepted answer does work I found that if you added text into an XIB file and then set the font to our new font then the text didn\'t update.
Making sure the new font is included in resources fixed this problem (taken directly from walkthrough):
\"This should not be a problem but sometimes when you’re having trouble getting your font face to show up, this can be a source of headache so let’s double check now to rule it out as a potential pitfall.
Go to your project Build Phases pane by highlighting the XCode project file in your solution explorer and on the right hand side, select “Build Phases”. You’ll see that one of the sections you can expand is “Copy Bundle Resources”. Open that list and make sure that your fonts are included in that list.\"
The other stuff in the walkthrough is the same kind of stuff (add the file to your project and to the plist file too)
All credit to Code with Chris for this answer which saved me a lot of time and effort and I am merely copying a shot from his page to allow this answer to stand on its own feet instead of requiring you to click the link.
Don\'t forget to add the fonts to the targets compile bundle resources by going to \'Targets\' -> \'Build Phases\' -> \'Copy Bundle Resources\' and add all the fonts manually
Most of the time we forget to add font to the application Target. Make sure you did not forget this important step. Mind checking right panel File Inspector > Target Membership checkbox.
Also you can check wether font is added well to your application or not by running this code snippet in anywhere on your app.
for (NSString* family in [UIFont familyNames])
{
NSLog(@\"%@\", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(@\" %@\", name);
}
}
EDIT
ALPHABETIC 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 a list of available fonts in your app, where your added font will also appear.
I think is better for a dev to have the plist structure as raw source code. I\'m leaving it for 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 modify the strings keys into the array to your desired fonts. Hint: To view the plist as raw source code please click secondary button over 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 the fonts could be useful to add to (for example) the AppDelegate.m class to see what are the real fonts names (on the bundle). A problem I encountered various times that I was loading the fonts with a wrong name assuming that the font filename as the correct one. Sometimes it differs from the bundle real name. In addition to this you can check the file full name using the file info window (cmd+i) on finder (macOS).
Example to clarify:
File Name = \"DroidSansEthiopic-Regular\"
Processed Name in bundle = \"Droid Sans Ethiopic\"
In Xamarin iOS
Step 1:
First of all you have to add your .ttf
or .otf
file into your Project.
like Roboto-BoldItalic.ttf .
Step 2 : Right click on the Font and select property
Step 3:
go to info.plist
select property Fonts provided by application
and add the font name.
Step 4:
set Font programatically below way
account.Font = UIFont.FromName(\"Roboto-BoldItalic\", 18f);
You can use [UIFont fontWithName:@\"ArialMT\" size:14];
method directly, if you want to change your font style. Also all the fonts may not be available in iphone library.Just refer this for available font styles.
If you have .otf format. sometime this format doesnt work. Convert .otf format to .ttf. There are bunch of font converter online. Once you add the custom font to your .plist file under Fonts provided by application as explained above. Make sure in your Project Target under Build Phase -> copy Bundel Resourse that file is present. If not then add it. Then just in your code add this [UIFont fontWithName:@\"your custom font\" size:your choice of size];
Steps to add font to your Xcode
Select your UILabel, UITextField or whatever then under fonts section and follow
Step 1
Select settings menu from left corner of font selection screen. And choose font manager option.
Step 2
Click on the add button as marked below.
Step 3
Select the folder that contains your font. It will be loaded into XCode fonts list.
Steps to add fonts to your project
Don\'t forget to add description to your plist with the key Fonts provided by application.
and put font files inside copy bundle resources under project target settings.
Yes! thats it.. njoy..