How to use custom fonts in iPhone SDK? [duplicate]
Asked Answered
E

4

48

I Want to implement custom font in my app. So i have added that in my Project Source code. I don't want to set that programatically. Is this possible that I can do this with setting properties in xib?

Endrin answered 17/1, 2013 at 10:27 Comment(4)
No, this can be done only one runtime, you need to set in your code programmatically only..Mathura
[see this link , might help you] #4969829Keil
codefriends.blogspot.in/2012/04/…Hence
check this linkDuodenitis
G
138
  1. Add your custom font into your project , i.e. Dragged the font file(CALIBRIZ_0.TTF) into XCode project.

  2. Edit Info.plist: Add a new entry with the key "Fonts provided by application".

  3. For each of your files, add the file name to this array

    enter image description here

  4. Opened the font in font book(double click on your font in finder) to see what the real filename is and I see this:

enter image description here

Now set font to your label

yourLabel.font = [UIFont fontWithName:@"Calibri" size:15];

Follow this to get more

Grantgranta answered 17/1, 2013 at 10:34 Comment(4)
Nice!! its work for me.Bundle
Make sure the fonts are in your Copy Bundle Resources. Other wise it won't work!Dispassion
Also make sure to use the System Name of the Font, not the name of the fileCrucifer
Also make sure you use the name of the font NOT the name of the file.Hofstetter
H
24

I think you had not searched well.

How to add CUSTOM fonts:-
Steps:-
  1.  Add your custom font files into your project using XCode as a resource
  2.  Add a key to your info.plist file called "Fonts provided by application".
  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 theUIAppFonts array
  5.  Save info.plist
  6.  Now call UIFont *fontCustom = [UIFont fontWithName:@"CustomFontName" size:12];  to get the custom fonts.

NOTE:- Make sure the fonts are in your Copy Bundle Resources.

For example:- If you want to use "Nexa Light" font in your app, then add "Nexa Light.otf" into your project and call in this way.

UIFont *fontCustom = [UIFont fontWithName:@"Nexa Light" size:14];
lblName.font = fontCustom;
Higherup answered 17/1, 2013 at 11:8 Comment(1)
adding every font file to Target is also an important task.Beora
T
11

Step 1:
Copy the font file to your resource files. Make sure it is added to Copy Bundle Resources in your Build Phases settings.

Step 2:
In your Info.plist just configure this like below this screen

enter image description here

Step 3:

Access and use it with the following code:

UIFont *font = [UIFont fontWithName:@"YOUR_FONT" size:10];
Tenterhook answered 17/1, 2013 at 10:39 Comment(1)
Following code is for To Know exact font name after being install in system. let fontFamilies = UIFont.familyNames for fontFamily in fontFamilies { let fontNames = UIFont.fontNames(forFamilyName:fontFamily) print("(fontFamily) (fontNames)") }Hildy
H
11

Use font name from .ttf file

and you can also find from this link

after add this font name with it's extension like (OpenScan.ttf) in to .plist file

enter image description here

After add this font to .plist file, you can use it by

[self.txtField setFont: [UIFont fontWithName:@"OpenSans" size:13]];

And for more information read my Answer Adding custom fonts to iOS app finding their real names.

Hence answered 17/1, 2013 at 10:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.