Steve Reed Sr
Steve Reed Sr

Reputation: 2021

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?

Upvotes: 4

Views: 2970

Answers (3)

Gorm
Gorm

Reputation: 2754

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/

Upvotes: 0

topace
topace

Reputation: 1791

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:

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

  2. 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/

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

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

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

Upvotes: 7

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 imagealt text.

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.

Upvotes: -1

Related Questions