Use custom font - iphone

How to use custom font?(font that doesn't exist in iphone)

Since you mention iphone-sdk-4.0 as one of your tags, it means that you can use the UIAppFonts key on your app. UIAppFonts was introduced on iOS 3.2.
The key to be added on your property list: http://developer.apple.com/library/ios/#documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW3
UIAppFonts description.

Ex.
Add the font files to your resource files
Edit your Info.plist: Add a new entry with the key Fonts provided by application.
For each of your files, add the file name to this array
First you can install a custom font in your app pick original font name
then rename your font file name.
[LblTwitter setFont:[UIFont fontWithName:#"The Great Escape" size:12]];
Note: this is available in iOS 4.0 and later.

You will have to include your font file in your project and update the keys in info.plist after that you can use that font by name see this link

Related

iPhone muliti laanguage support application

I wanna create my iPhone app in three languages. English & Punjabi & Gujarai.
"Gujarati" & "Punjabi" is not available in locale list of languages. so i can't able to create values folder like values-fr(french) and value-rs(russia).. like dat.. How can i develop this app with "Punjabi" & "Gujarati"?
IOS 4.3 onwards these fonts are supported : http://iosfonts.com/
If don't find the fonts then you can use custom fonts. Steps listed below
Just follow these steps:
1.Add your custom font files into your project using XCode as a resource
2.Add a key to your info.plist file called UIAppFonts.
3.Make this key an array
4.For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array
5.Save info.plist
6.Now in your application you can simply call [UIFont fontWithName:#"CustomFontName" size:12] to get the custom font to use with your UILabels and UITextViews, etc…

Custom font is not working in my App?

In my iPhone app,
I have included two custom fonts and by referring this steps by stackoverflow questions....
How to include and use new fonts in iPhone SDK?
And Coded ....
[lbl setFont:[UIFont fontWithName:#"glyphish.ttf" size:[lbl minimumFontSize]]];
I am building this app for Base SDK 5.0
The answer is,
[lbl setFont:[UIFont fontWithName:#"glyphish" size:[lbl minimumFontSize]]];
Thanks to all.
First find that font in your available fonts list:
NSLog(#"fonts: %#", [UIFont familyNames]);
Then find and input the appropriate name.
You have passed a filename (glyphish.ttf) instead of the actual font name. Most likely, the font name is Glyphish, but you need to query it somehow: either using the Mac's "Font Book.app" or via code: first, you need to query the family names via [UIFont familyNames]. Then, use [UIFont fontNamesForFamilyName:] to get the actual font names to load. For example, if your font contains a bold variant its family name would be Glyphish but font name would likely be Glyphish-Bold.
You should correct name. It should not contain ttf in glyphish.ttf. For exact reference refer following image for that. Dakota is font name in my case.
The font name is not the name of the file. Thus glyphish.ttf is not a valid font name.
you have to use the font name, not the filename. you can check the name by opening the font file on yout mac.
Most probably the actual font name to be put in the app might be something else than glyphish.ttf .. i suggest opening font book and there checking the name of the font .and using that.
You need to check the font name it may be different then the font file name...try this link
Go to your application build phases and add your font files in copy bundle resources
Double click on the font file to open it in font book. Now see the name of the font on the top bar. Use this name in your code.

How to use FUTURA-Bold font in my iPhone app

I am trying to use FUTURA-BOld in my app but its not working as it should be. I installed the font in my system, copied the font in my code resource. Edited the info.plist with the font name. And choosing the same font but it is just giving me simple font.
Any idea ???
Thanks,
1) Have you made the plist entry UIAppFonts of type array, putting your (ttf) filename as a member value?
2) Are you using the actual internal font name? This may differ from the ttf filename. Use
NSLog(#"fonts: %#",[UIFont familyNames]);
to get a list of fonts. Lookup your font and use that name exactly.

How to include and use new fonts in iPhone SDK?

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?
Add the font files to your resource files
Edit your Info.plist: Add a new entry with the key Fonts provided by application.
For each of your files, add the file name to this array
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.
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"
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.
Its Easy and simple now- Tested in Xcode 9.2 and swift 4
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..
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];
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
Build Action --> Content
Copy to output directory --> Always Copy
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);

ttf font not available for iPhone in interface builder or simulator

I added a font file (.ttf) to my Xcode project, to resources. Also, I added it to the UIAppFonts in my info.plist.
When I want to use this font though, I don't even see it as a choice in IB.
After installing the font on my system, I started seeing it in IB, but still - changing to it doesn't change anything - some default system font is displayed in the Interface Builder as well as in iPhone emulator.
Are there any steps more I should do to be able to use my own font?
To use custom fonts with iOS you have to set them programmatically.
For example, suppose you have a font file called swellfont.ttf that you add to your project.
You then would go into your App-Info.plist file and add the full name of the file to the next index of the array keyed by UIAppFonts, as you mention.
<key>UIAppFonts</key>
<array>
<string>swellfont.ttf</string>
</array>
Then, to use the font:
label.font = [UIFont fontWithName:#"swellfont" size:12];
Assuming that label is a UILabel and that swellfont.ttf is not protected. It's important to note that UIFont's fontWithName is not referring to the filename, instead its wanting the actual name of the font. If you open the font with FontForge you can see this information by selecting Element > Font Info from the menu bar. There are probably cleverer ways to find this information out.
I use 2 fonts in an APP. The first one was automatically added to the "Copy Bundle Resources", the other was not. I had to add that one myself.
Call in code:
[labelName setFont:[UIFont fontWithName:#"OneGreatBigFont" size:40]];