I'm trying to use this font in my app. I've added it to the plist and to the project, but for some reason it is not loading on the label. I've tried to verify the font in the project with:
NSLog(#"DK Crayon Crumble: %#",
[UIFont fontNamesForFamilyName:#"DK Crayon Crumble"]);
But I'm getting this output:
DK Crayon Crumble: ( )
I found the problem. For some reason Xcode it was not copying the font file to the bundle package.
The convention with the built-in fonts (you can select them in Interface Builder) is that you eliminate the spaces and add the attributes after a hyphen, such as
#"HelveticaNeue-Bold"
for Helvetica Neue, Bold.
I don't know the exact name of your font but if you follow this scheme, it should work.
Some times the fonts are visible in the project file but are not actually
added to the target to do so
click on the project's name -> click on target -> Build Phases, go to
'Copy Bundle Ressources', if the concerned font(.ttf extension) file is not there add it to the list.
Clean your Project and run you should be able to see the font.
Maybe the problem is that the name of font is with space. Remove spaces, in real file name, add it again to your plist and try again with code:
[UIFont fontNamesForFamilyName:#"DKCrayonCrumble"];
This link help you to set font:
set custom font
Related
So I'm having a couple of problems actually. The first is that I want to use a "Font Suitcase" file as a custom font in an iOS app and haven't been able to get it to work. Not only that, but I haven't been able to properly use a .ttf file either. Here are the steps that I've taken to try and make it work:
Imported the file into my supporting files in xCode.
Added the file name, e.g. "badaboom.TTF" into the Info.plist file
Called UIFont *myFont = [UIFont fontWithName:#"Badaboom" size:20.0];
I also used the code found here to see if the font was even being loaded and it doesn't appear either. This applies for both ttf and font suitcase files.
Any idea what I'm doing wrong?
Thanks,
Pete
You have to add your fonts as resources.
So do the following steps:
Go to your project settings
Select your target
Go to Build Phases
Add the custom font to Copy Bundle Resources
With this and the code you posted you should now be able to load custom fonts
Double click on the TTF file in Finder. Look at the title bar. The name inside preview has to be exactly the same as what is in your quote [UIFont fontWithName:#"" size:20.0];
It's case sensitive.
i need to use corbel and caliber font in textview , textfield and label in my new application. I have searched for it in google but i did not got any solutions . Can any one please help me. Thanks in advance.
Follow these steps:
1) Add desired fonts to Xcode as resource.
2) Open info.plist file. Now create a key called UIAppFonts and make it an array. Add the filename of the font as a value.
<key>UIAppFonts</key>
<array>
<string>corbel.ttf</string>
</array>
3) Save info.plist FILE.
4) To use the font in your application add this line.
[UIFont fontWithName:#"corbel" size:32.0]
Courtesy :
Can I embed a custom font in an iPhone application?
CUSTOM FONTS IN IOS.
P.S. But to determine the exact name of font put temporary line of code as even small case sensitivity might cause a problem loading fonts.
NSLog(#"%#",[UIFont familyNames]);
This will print names of all the fonts on the device. Find the one that matches your font.Whatever the font name you get use it in the line in Step 4.
Courtesy: How do I include a font with my iPhone application?
You can add custom fonts to Xcode, I think this article can help you out doing so. I also found this video. As for the caliber and corbel files, a quick search in google will get what you want: corbel caliber tff.
Install same font in Mac OSX and try to find same font name in textedit application.
type exact spelling (with case sensitivity) in Xcode.
some time it happens font file name is different and we type it differently.
put the exect file name in plist file... but use the installed font name in application (Xcode.)
I'm trying to use a custom font (Sassoon Infant) in Xcode. Despite looking at the numerous posts here on this issue, i haven't been able to resolve the problem.
These are the steps i have taken so far.
Added font to resources
Added font to Font Book
Added SassoonInfantCom-Regular.ttf to Fonts Provided by Application
Tried using fontWithName:#"Sassoon Infant Com", the name in Font Book
Also tried just #"Sassoon"
The font name is not showing up in IB either under the dropdown font menu. The above seems to work for most people but i can't get it working. Anyone have any ideas?
Remove the extension .otf / .ttf from the file and the plist.
Also make sure you are editing the correct plist file for the "Fonts provided by application property"! I spent two days trying everything to make some custom fonts work. Then I realised I was editing the APPTest-info.plist (which is in the resources folder of the Tests folder in XCODE) instead of editing the APP-info.plist file!
In my defence, both files are really close to each other in the files navigator in Xcode... ;-)
I just added it into the bundle and did this
myLabel.font = [UIFont fontWithName:#"MyCustomFont" size:19];
MyCustomFont being a .ttf file.
Hope this helps.
Make sure that the font is added to your target. Select the font and check the target membership in the left Xcode sidebar.
Make sure that you got the correct font name. Open the font in "Font Book" and see its name.
I am attempting to use a Font Suitcase for a custom font in an iOS4 app but am not having any success.
I have read other posts that have documented how to use custom fonts, so have copied the suitcase into my project, added it to resources and the Info.plist '
Fonts provided by application' array, and attempted to use it both in Interface Builder and in code. But it doesn't work!
All examples I've found regarding custom fonts show using them with ttf or otf files, but nothing with a suitcase. Can it be done? If not, how do I get something out of the Font Book into a file structure that can be used as a custom font?
I had the same problem and just solved it. Friend gave me a couple of fonts zipped, I unzipped and then the file sizes are zero kb and I couldn't install them into Font Book.
So I googled and found out that my friend should have used StuffIt Expander to zip. So he sent me the file again, and I used StuffIt Expander to unzip. I was then able to install the fonts into my Font Book.
However, the fonts are still not usable in my iOS app. So below is what I did:
I found out I need to convert the font, so I installed Fondu
http://fondu.sourceforge.net/
The installation ended up saying not successful, but later I was still able to use.
Then I realise I need Rosetta to run Fondu, so I looked at the instructions on this page.
Got my Snow Leopard CD out and install optional package
http://www.macobserver.com/tmo/article/snow_leopard_installing_rosetta/
Open Terminal and go to the directory where your font is. Type the command:
fondu [font file]
Then you will get a prompt asking if you want to save [font file].pfb
Choose yes.
Now in your XCode, add the pfb file into your project. Then go to info.plist and add the file to UIAppFonts (include the .pfb extension).
I tested the font in a UITableViewCell
cell.textLabel.font = [UIFont fontWithName:#"[font file]" size:30]; // do not include .pfb extension
And the font is showing up fine. I initially thought iOS will require a .ttf file but looks like .pfb is fine also.
Hope this helps.
Additional testing tips:
Once you add the UIAppFonts plist array as shown above add a breakpoint in your appDidFinishLaunchingWithOptions method and at the console type
po [UIFont familyNames]
That gets you a list of installed fonts so search for your font family name. Copy that and paste it into this:
po [UIFont fontNamesForFamilyName:#"familyname"]
This gets you the font name you reference in your code. I've not tried the [font filename] approach but this gives you the name the app uses to reference the exact font you want. This is important when a font contains a series of variants or you have multiple installed from the same family. For example helvetica has four variants so you can pick the right one this way:
lblMyLabel.font = [UIFont fontWithName:#"fontname" size:lblMyLabel.font.pointSize]
E.g.
lblMyLabel.font = [UIFont fontWithName:#"Helvetica-Oblique" size:lblMyLabel.font.pointSize]
This keeps the font point size you used originally for the label. I've also only had success once the view is loaded.
This solution doesn't require Fondu or Rosetta, but it does involve a little cut-and-paste into macOS's Terminal app.
Pretty simple, and free.
https://sittingduck.co.nz/2013/11/unpacking-the-suitcase/
First of all include SystemConfiguration framework to your project. And also add ttf or otf file as per your requirement. Then import dlfcn.h file to delegate implementation file. And you have to call the function after that as attached in the image.
And then you can access in your controller wherever you want to use the custom font. You need to just pass font in fontwithName: method of UIFont.
It looks like there a few working solutions for using custom true type fonts (ttf) on the iPhone, most notably Can I embed a custom font in an iPhone application? However, this method does not support open type fonts (otf).
Has anyone come across a way to make use of otf typefaces?
For my own project I wanted to use the opentype font and I basically used this method:
Add your custom font file into your project using XCode as a resource
Add a key to your info.plist file (Fonts provided by application)
For each font you have, enter the full name of your font file (including the extension)
save info.plist
then use this for your labels (ex:)
UIFont* font = [UIFont fontWithName:#"Harrowprint" size:20];
In my case #"Harrowprint" was the filename without the extension and not the font name provided by Finder.
My font was an otf and it worked...so I guess it's supported...or I was lucky. I'll test another font..and keep you posted..
references:
http://blog.beefyapps.com/2010/06/custom-fonts-in-ios-4/
Can I embed a custom font in an iPhone application?
Must you use an otf font on the device or can you convert it to ttf? It is relatively straightforward to convert an OTF font to a TTF font using a tool such as fontforge, perhaps that would be an easy solution.
I had trouble with this, too. Here is what worked for me:
Copy the font files into the Resources.
Check to see that the font files are in 'Build Phases'->'Copy Bundle Resources' (Xcode put them there for me when I added the files to the Resources. If, for some reason, they are not there, add them.
Add the filenames to your info.plist file as describe above. Include the extensions.
Open Font Book, select your font and Preview-Show Font Info and look at the 'Family', e.g., 'Foo'
Put this in your code somewhere and set a breakpoint to check the array of names: NSArray *names = [UIFont fontNamesForFamilyName:#"Foo";
Run your app and when it breaks, right-click on the 'names' variable in the debugger. This will show you the font names to use, e.g.: <__NSCFArray 0xe9c4da0>(
Foo-100Italic, Foo-100 )
Note that my font names were not shown
correctly anywhere else, not in the filename nor in Font Book.
You should be good to go with:
myLabel.font = [UIFont fontWithName:#"Foo-100Italic" size:24];
This article answers your question (it worked like a charm for me using OTF):
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
OTF is perfectly supported, no need to convert to TTF
With regards to the first answer - the solution is correct (i.e. just convert the font over to TTF) but the software suggested is a super hassle to compile and install. Instead I just did a quick google search and used this instead: http://www.freefontconverter.com/ and that worked perfectly.
(Make sure to add the font to your info.plist file as well)
I researched this throughly, and this is the best method I found:
1) Convert font file to TTF using this online tool: http://www.freefontconverter.com/
2) Add the TTF files to your project
3) Make some configurations to your info.plist file:
3.1) Edit info.plist as source code (right click on file -> open as -> source code)
3.2) Add this:
<key>UIAppFonts</key>
<array>
<string>font1.ttf</string>
<string>font2.ttf</string>
...etc...
</array>
3.3) Your info.plist should have this now:
4) Use the new fonts just like the system fonts:
[UIFont fontWithName:#"font1" size:16.0];
(Notice no ".ttf" in the font name)
You should use the font names, not the font file names. To get the font names, run
for family in UIFont.familyNames {
print("font family", family)
for names in UIFont.fontNames(forFamilyName: family) {
print("font name \(names)")
}
}