Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom fonts in iOS 7

Tags:

ios

iphone

fonts

I'm developing a game and I would like to use a custom font in my app. I'm using SpriteKit for it, if that's important. I've tried using this https://github.com/deni2s/IBCustomFonts but I cannot get it to work with this font http://www.fontspace.com/freaky-fonts/emulogic

I've tried various things, and I've registered the font on the info.plist of the app... Does anyone know what's going on?

like image 839
José María Avatar asked Feb 12 '14 19:02

José María


People also ask

How do you get different fonts on iPhone 7?

You can download fonts from the App Store app , then use them in documents you create on iPhone. After you download an app containing fonts from the App Store, open the app to install the fonts. To manage installed fonts, go to Settings > General, then tap Fonts.

How can I make my own font for iOS?

In Pages, tap the paintbrush icon at the top and select the name of the current font from the formatting pane at the bottom. Browse through the list of fonts and you should see both the built-in system fonts and the custom fonts you installed. Tap the font you want to use and then close the formatting pane.

What font does iOS 7 use?

iOS 7 uses Helvetica Neue Ultralight font but you can also download the font icons.


1 Answers

First of all I'm assuming that SpriteKit doesn't make any difference.

  1. You need your font in .otf or .ttf copied to your project. For example in Supporting Files.
  2. You need to edit .plist file. Add "Fonts provided by application" key into your plist and in Item 0 copy the exact filename of the font you copied to your Supporting files WITH extension. For example: "JosefinSansStd-Light_0.otf"
  3. Make sure that the font you imported to your app is being packed into app itself. Do that by selecting your Target, then Build Phases, then Copy Bundle Resources. If you don't see your font in there, drag it from Supporting Files.

Finally, you would like to list all your fonts when the app starts just to see useable name for your font. You will do that with this little piece of code:

NSArray *fontFamilies = [UIFont familyNames]; for (int i = 0; i < [fontFamilies count]; i++) {     NSString *fontFamily = [fontFamilies objectAtIndex:i];     NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];     NSLog (@"%@: %@", fontFamily, fontNames); } 

Search for your font in printed results, for example, I would search for "Josefin" and I would see that actual font name is "JosefinSansStd-Light". After that you only need to use that font by:

UIFont *customFont = [UIFont fontWithName:@"JosefinSansStd-Light" size:20]; 

In iOS8 you add your fonts directly to the project and they are visible in the interface builder. Modify your code to account for this but programmatically setting font for iOS7 and selecting it in xCode6 interface builder. PS. Interface builder in xCode6 gives you the correct font name that you can copy-paste into the code below.

#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)   if(SYSTEM_VERSION_LESS_THAN(@"8.0"))     {         UIFont *customFont = [UIFont fontWithName:@"OpenSans-Light" size:32];         self.registerLabel.font = customFont;       } 

Hope this helps, cheers.

like image 92
jovanjovanovic Avatar answered Sep 23 '22 11:09

jovanjovanovic