Using a custom font in Xcode - iphone

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.

Related

iOS custom fonts not working

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

Loading Custom UIFonts in xCode

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.

how to use corbel and calibri font in Xcode

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.)

Add Custom Fonts In Xcode 4.1

i want to use custom fonts in y application.
i have declared the "Fonts provided by the application" in the info.Plist file
and set the label.font to the font with name with / without the .TTF extension
draged the TTF file in to the project and copied the file to the project
created an outlet to the label but still, nothing works.
if someone knows what is going on over there i would like to get some help.
recently i have noticed the this problem are known # the 4.1 (xcode version).
TNX :)
The font name isn't the name of the file. What you want to do is double click on the font in Finder.
This should open it in Font Book like this image
The font name you want is the one in the title which I've highlighted so attractively in red.
I just spent a big chunk of my day trying to figure my problem out... what I missed was, when I dragged the .ttf file into xcode, I did not select my app's name under "Add to target:" section.
Even though it seemed as if the file was in the correct directory and what not, it wasn't recognising it under the family names, using this code:
NSLog(#"FONT FAMILIES\n%#",[UIFont familyNames]);
So hopefully this can help someone if they're stuck.
The above advice did not work for me, so I wanted to share what did:
Opening the font in Finder gave a long name that did not work (TypeWrong Smudged - DGL), but when I looked for the same font in the Photoshop font list it showed the name as just TypeWrong, which did work. So if Finder shows a long name with spaces in it, you might want to try just using the first space-free chunk.
You have to check what is the font name it is at times different from font file name...
check this link

iPhone Custom Fonts with Font Suitcase

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.