4thSpace
4thSpace

Reputation: 44312

Using fonts that aren't on iPhone

I'd like to use some fonts that aren't part of the iPhone OS. I've seen games that use non standard fonts. I can install the fonts, create images for each one in Photoshop and then use those images in the iPhone app. However, I don't think that is a practical way to go. If the color or tint needs to be adjusted (because of background) or size, I'll have to redesign every font I'm using. Is there a better way to do this?

I read this Can I embed a custom font in an iPhone application? and downloaded the open source font label app. However, it crashes most of the time when I try using particular fonts. In regards to the last comment about using UIFont with the fontWithName:size, that certainly doesn't work. Your font variable will be nil. Listing all available fonts reveals why - none of the custom fonts are in the list.

I've also read How do I include a font with my iPhone application?, which definitely does not work. Same as last comment in above link.

Upvotes: 6

Views: 10186

Answers (4)

hypercrypt
hypercrypt

Reputation: 15376

This is actually quite easy.

You include your ttf in the app bundle. You add the Fonts provided by application / UIAppFonts key to your application, this is an array of file names for fonts you are including (including the extension) e.g.:

enter image description here

You can the use the font quite easily using UIFont:

self.label.font = [UIFont fontWithName:@"Wingdings" size:23.0f];

This works on all iOS versions from 3.2, including on the iPhone from iOS 4.

Upvotes: 2

james_womack
james_womack

Reputation: 10296

The correct answer is to use FontLabel, which can be found on GitHub. http://github.com/zynga/FontLabel

I've used that code in several real-world project and it's absolutely fantastic.

UPDATE:

As of iOS 3.2 (iPad only) & iOS 4 on the iPhone, you can package TTF fonts within your app bundle. After entering them into your Info.plist using the UIAppFonts key.

Three step instructions here: http://kgriff.posterous.com/45359635

Upvotes: 7

RichX
RichX

Reputation: 494

The solution is to add a new property "Fonts provided by application" to your info.plist file.

Then, you can use your custom font like normal UIFont.

Upvotes: 3

Gordon Christie
Gordon Christie

Reputation: 609

This sadly is not an immediate answer, but it seems that in the future, you will be able to include custom fonts as part of your app:

UIAppFonts (Array - iPhone OS) specifies any application-provided fonts that should be made available through the normal mechanisms. Each item in the array is a string containing the name of a font file (including filename extension) that is located in the application’s bundle. The system loads the specified fonts and makes them available for use by the application when that application is run.

Unfortunately, this works only in iPhone OS 3.2, which is the iPad specific version. It does seem very likely that this feature will be available in future iPhone OS releases.

Link: http://developer.apple.com/iPhone/library/documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW18

(this was the only public documentation I could find on Apple's site)

Upvotes: 0

Related Questions