Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Fonts in Xcode 5

Tags:

How would you add a custom font in Xcode 5 and how would you change every label in the project to that font? Because I've heard you can only do this programmatically?

like image 437
Mr Big Problem Avatar asked Sep 22 '13 08:09

Mr Big Problem


2 Answers

You need to set every label programmatically with your custom Font.

To use custom font :

1/ add your custom font in your project like resources (font .ttf or .otf)

2/ in your info.plist add key UIAppFonts (Fonts provided by application) and and the name of each custom font (for example : SohoGothicStd.ttf)

3/ you can create macro for use your font

#define FONT_SOHO_STD(s) [UIFont fontWithName:@"SohoGothicStd" size:s] 

4/ use this macro for a label par exemple :

_myLabel.font = FONT_SOHO_STD(15.0f); 
like image 89
Jordan Montel Avatar answered Oct 17 '22 03:10

Jordan Montel


I believe you need to use [UILabel appearance] proxy to set custom font for all labels across your application. Add following lines to your AppDelegate didFinishLaunchingWithOptions function to set custom font for all UILabels in your project.

UIFont *newFont = [UIFont fontWithName:@"My-Custom-Font-Name" size:14]; [[UILabel appearance] setFont:newFont]; 

NOTE: You need to make sure your fonts are in your Xcode project.

Here are the steps you can follow to add custom font to the project.

  1. Add your custom font files into your project using Xcode as a resource
  2. Add a key to your Info.plist file called UIAppFonts.
  3. Make this key an array
  4. For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array
  5. Save Info.plist

Steps taken from: Can I embed a custom font in an iPhone application?

like image 34
Yas Tabasam Avatar answered Oct 17 '22 03:10

Yas Tabasam