Load TTF font from external path - iphone

I was wondering that how to load a TTF font from a absolute file path, not relative, which is usually done with
[UIFont fontWithName:#"xyz"];
In cocos2d we can do it by using CCLabelBMFont that takes file as parameter, but when use CCLabelTTF it takes the name of font, not the file name.
Is there any workaround to load an external font not embedded with the application but downloaded from some resource as per need ?

Yes, you can do this.
Just copy the font to your project and add this reference in your info.plist. Then you can reference the font name just like any other system font.

if I did well understand your question, maybe this post Can I embed a custom font in an iPhone application? will give you an answer.

Related

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 load font from disk?

Is it possible to load a font from disk and use it during run-time?
If so, how/where do you store the fonts on the iphone/ipod/ipad for your app to use?
(To be clear, I'm not talking about adding the font as a resource at design-time. I'm asking about a way to allow a user to select a font file during run-time, loading it, and making it available for use.)
You should put them (.ttf, .otf) into your info-plist under UIAppFonts then you can "use" them with setFont: withSize:
You add your font as a resource, add it to your info.plist under Fonts provided by application (UIAppFonts) array, then use it as any embedded one.
Ok, in that case take a look at FontLabel project.
One thing though, looking through it's code - you can only get CGFontRef and with kind of voodoo work with it, no conversion between CGFontRef and UIFont really exists. See this question

Custom font in iphone not being displayed properly

I installed a custom font called "modern no. 20" (already installed in my mac) into my iphone project .
I copied the modernno20.ttf into my resources.
Now in my app-info.plist i added this font name in "Fonts provided by application".
Then i added
cell.textLabel.font=[UIFont fontWithName:#"modernno20.ttf" size:14.0];
in my tableviewcode .
i dont know why but this font is not properly displayed.is there any thing i missed?
In order to call the font in your fontWithName call, the string should be the name of the font as it is displayed in the Mac's 'Font Book' app, and not the actual filename of the referenced font file.
There hasn’t been an easy way to add custom fonts to your iPhone applications. As of iOS 4 it has become very easy to do. there could be possibility you would have missed some of the step to get custom font work.
Here is what you need to do in order to add custom fonts,
Check How to include ttf fonts to iOS app

Custom font doesn't work in interface builder!

I've downloaded a font that's called "aldo the apache (.tff) " from dafont.com.
I used it with different programms like adobe illustrator and it seemed to work just fine.
Recently i tried to use it in a game that i'm making to experement. It didn't work -_-.
IB was displaying the font as a slightly bigger version of arial.
How can i solve this problem and get the font to display correctly?
If you have any suggestions, please post them down below.
-DD
You have to edit your <appname>-Info.plist file and create a new UIAppFonts key with type array, where each element is a String with the name of your font file, in this case AldotheApache.ttf. Then use the name in IB or with UIFont as it shows in the application Font Book app of your Mac, in your case Aldo the Apache. Obviously the font should also be added as a resource of your project.

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.