55

I am trying to use custom font (Bebas Neue) in my iOS application. The steps I took are:

  1. Copy the .otf files to the project.
  2. Confirm the .otf files have set the project as target.
  3. Added the .otf files in 'Fonts provided by application' in plist.
  4. In Build Phases, the .otf files are in 'Copy Bundle Resources'.
  5. Install the font on my Mac.
  6. Try to print out all fonts available but I can't see my custom font.

The code I used:

for name in UIFont.familyNames() {
  println(name)
  if let nameString = name as? String
  {
    println(UIFont.fontNamesForFamilyName(nameString))
  }
}
  1. Trying to set the font in code and it worked.

The code I used:

textLabel?.font = UIFont(name: "BebasNeueRegular", size: 14)
  1. But I can't set it in interface builder. Any idea?

Screenshots:

Font Font-List

chengsam
  • 7,315
  • 6
  • 30
  • 38
  • There is a easy way to check whether your custom font available to your project.Just place an UILabel into your mainStroryBoard. Select label and goto font manager select custom and check your custom font listed in the font list.if your custom font listed in the list then the font available to your project.if not then something wrong with your font import.i recommended you to import few more fonts to your project (otf and ttf) and see that works.... – Joe Oct 21 '16 at 05:18
  • If you still having issue. post screenshot of your plist. Most likely your plist could be a culprit... – Joe Oct 21 '16 at 05:21
  • @Joe Thanks for your response. I have tried to place an UILabel and select custom in font, but I cannot find my custom font. I have tried using other font and I can see the other font in interface builder. Maybe there's some problem with this font (Bebas Neue)? – chengsam Oct 21 '16 at 05:37
  • I know what's your problem did you change the font name after you import viseversa. Can you update this line with your current font name textLabel?.font = UIFont(name: "FontName", size: 14) – Joe Oct 21 '16 at 05:57
  • textLabel?.font = UIFont(name: "BebasNeue", size: 14). Try this, it should work and ur plist font name should be like this BebasNeue.otf – Joe Oct 21 '16 at 06:02
  • @Joe I've updated my code. As I mentioned, I can set the font programmatically, but I want to set the font in interface builder also. – chengsam Oct 21 '16 at 06:03
  • let me make it clear .BebasNeueRegular is a BebasNeue font sub font they not same as u think. if you want to use BebasNeueLight then you have download and import to your project...hope you understand...ok.i will test ur font and update my screencast.... – Joe Oct 21 '16 at 07:27
  • Maybe you can download this font: http://www.dafont.com/bebas-neue.font and see if can be found in interface builder. – chengsam Oct 21 '16 at 07:32
  • font downloaded from http://www.dafont.com/bebas-neue.font – Joe Oct 21 '16 at 07:33
  • Can you find it in Interface Builder (storyboard)? – chengsam Oct 21 '16 at 07:33
  • Why you fuzz about the particular font. there is million font out there mate..In my end everything works..... try to command+option+shift+k to clean your build folder and close Xcode and try again.... – Joe Oct 21 '16 at 07:44
  • Sorry to spend your time guy..Let check my added screenshot, if you do not have my problem and you can use it interface builder, then it's my problem and I'll try to solve it on my own. Thanks. – chengsam Oct 21 '16 at 07:46
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/126303/discussion-between-joe-and-chengsam). – Joe Oct 21 '16 at 08:35
  • @chengsam did you solve your problem ? It happens to me too for this exact font and I don't know how to fix it, tried everything I could think of... – Pierre Mardon Nov 03 '16 at 13:49
  • You can only do this programmatically, I still can't managed to use this in Interface Builder. – chengsam Nov 07 '16 at 02:57
  • @chengsam did you try to open "Fonts" on Mac, remove your font and then add it again? Maybe it will help.. – Eridana Nov 22 '16 at 05:56
  • Check my update....my update clearly explains how to access 'BebasNeue' font from interface builder. – Joe Nov 24 '16 at 01:07

11 Answers11

65

Try Below Steps: Code tested in Swift 3.

Step 1: Add Your custom font into your project( Make sure Add to Target ticked).I am using "PermanentMarker.ttf","Pecita.otf" and "AROLY.ttf" font as a test font.

Note: Supporting font Type ttf and otf (Both font types should work)

Step 2: Modify the application-info.plist file. Add the key "Fonts provided by application" in a new row and add "PermanentMarker.ttf" as new item in the Array "Fonts provided by application".

Your plist should looks like this

enter image description here

Now the font will be available in Interface Builder. To use the custom font in code we need to refer to it by name, but the name often isn’t the same as the font’s filename

Now, You can access the Custom Font from your viewController. I am testing the font by placing a UIlabel to the Storyboard like below.

Update 2: Working Solution

After, imported your custom font and updated your plist.selectlabel from your storyBoard,goto Attributes Inspectorunder Label>Text type> select to Attributed and choose your custom font from the list.

enter image description here

enter image description here

enter image description here

Output:

enter image description here

Update 1

If your custom font still not listed in Xcode font list.check the related link to your issue

Note: Still,You can assign BebasNeue or custom font programatically to your label or button etc. even its not showing in your interface Builder.If you having trouble setting font to your object programatically.try below method.

Assign font to UILabel:

    label?.font = UIFont(name: "BebasNeue", size: 35) // Set to any size

Assign font to UIButton:

    button.titleLabel?.font = UIFont(name: "BebasNeue", size: 35)

Assign font to UITextField:

    textField.font = UIFont(name: "BebasNeue", size: 25) 

Assign font to UINavigationBar:

    navigationController?.navigationBar.titleTextAttributes = [NSFontAttributeName: UIFont(name: "BebasNeue", size: 25)!, NSForegroundColorAttributeName: UIColor.red]

Assign font to UIToolBar:

    UIBarButtonItem.appearance().setTitleTextAttributes([NSFontAttributeName: UIFont(name: "BebasNeue", size: 25.0)!], for: UIControlState.normal)

Output:

enter image description here

Joe
  • 8,868
  • 8
  • 37
  • 59
20

Its Easy and simple now- Tested in Xcode 10 and swift 5

Steps to add font to your Xcode

Select your UILabel, UITextField or whatever then under fonts section and follow

Step 1

Select settings menu from left corner of font selection screen. And choose font manager option.

enter image description here

Step 2

Click on the add button as marked below.

enter image description here

Step 3

Select the folder that contains your font. It will be loaded into XCode fonts list.

Steps to add fonts to your project

Don't forget to add description to your plist with the key Fonts provided by application and put font files inside copy bundle resources under project target settings.

Yes! thats it.. njoy..

Community
  • 1
  • 1
Saranjith
  • 11,242
  • 5
  • 69
  • 122
  • 1
    YES, this is the way. I was able to include and use the font in the project, but the font wasn't appearing on the interface builder. Turns out xcode reads the font list from the system which indeed makes sense. NOTE: for anyone facing this problem, remember to include the font properly into your projects, otherwise it won't work on computers that doesn't have said font installed. – yeyo Mar 20 '19 at 14:23
  • I solved it by opening the Font Book app, then removing the Fonts from the "User" section, and finally dragging the font files to the "Computer" section (this required restarting Xcode). – Lluis Gerard Dec 11 '19 at 15:08
  • 1
    And what happens when the project gets installed on another persons mac, where these custom fonts are not installed? – Starwave Feb 03 '21 at 22:14
16

When using the same font (Bebas Neue), I experience the exact same problem: the font does not show up in the font list for Plain controls.

It does for Attributed controls, as described in Update 2 in Joes post, but then you're actually changing the attributedText instead of the regular text, which may lead to unwanted behavior. For example, you'll have to fiddle with NSMutableAttributedString to change the text or text color at runtime.

I did some investigation on this issue. I used FontLab Studio to modify the font and do some tests. I used Bebas Neue version 1.400 (dated September 15, 2014) from dafont.com.

  • Maybe the font file was somehow corrupted. Re-saved as .otf and .ttf: Didn't work.
  • Maybe the meta data of the font were corrupted. Copied all the glyphs to a new font and named that Bebas Neue: Didn't work.
  • I renamed the font from Bebas Neue to BN: It works! But why?
  • Maybe you can't use "Neue" in a font name (since Helvetica Neue was the iOS system font up to iOS 8). Renamed the font to Test Neue: Still works.
  • Maybe you can't use "Bebas" in a font name then? Renamed the font to Bebas: Still works.
  • What... Just to be sure, I changed the font name back to Bebas Neue: Doesn't work again.
  • I also tried BebasNeue: Also didn't work.
  • Then I changed the name to Bebas Neue Whatever: It works.

    Bebas Neue Whatever

I really do not understand why this is happening. Doesn't Apple or Xcode want you to use "Bebas Neue" or "BebasNeue" in the Interface Builder? I had the normal Bebas Neue installed. Maybe the reference got corrupted? I really can't tell. Maybe someone on a clean system can try if Bebas Neue works in their Xcode.

Anyway, I achieved my goal: being able to use Bebas Neue (I named the final version "Bebas Neue MyAppName") for Plain styled labels and buttons, so I can design my app as-is and don't have to fiddle around with attributed strings.

Flitskikker
  • 345
  • 2
  • 7
  • 2
    Same solution for me. Looks like Xcode doesn't like the font name until I change it's FullName metadata – Nick Jones Mar 20 '17 at 14:12
  • 3
    How are you changing the name? I am having the same issue with this particular font. – Buyin Brian Apr 03 '17 at 16:59
  • 5
    Since Bebas Neue is licensed under the SIL Open Font License that allows free redistribution, I uploaded a pre-renamed version of it that you can download here: http://ge.tt/14SV3fj2 Good luck! – Flitskikker Apr 12 '17 at 12:14
  • Thank you, this solution worked for me. I used a free program called FontForge to change the full name metadata (to "BebasFixNeue"): http://fontforge.github.io/en-US/ – kgaidis Dec 22 '17 at 14:29
  • Thanks @Flitskikker great!!!, your provided fonts worked for me. Can you please provide renamed font for BebasNeue-Bold, BebasNeue-Thin, and BebasNeue-Light ? – Sandip Patel - SM Jul 23 '18 at 14:28
  • i had same issue, and have hard time trying to use fontforge to convert the font. in the end i find this site http://www.glyphrstudio.com/online/ and convert the font there use this tutorial https://www.youtube.com/watch?v=RU_0-6eC4O0 – aiwiguna Nov 04 '18 at 14:04
  • In my case I just deleted spaces and now it works. something strange just with one font – Hrabovskyi Oleksandr Apr 11 '20 at 14:58
9

Finally, I found the root cause of issues with Bebas Neue fonts.

I don't remember where I have downloaded the fonts, but Bebas Neue fonts are inconsistent.

Download i.e. app called Typelight

Open not Regular, but i.e. Bold font with Typelight.

enter image description here

You need correct most of the Bebas Neue fonts.

János
  • 32,867
  • 38
  • 193
  • 353
  • Wasted a lot of time for this, thanks for posting :) I didn't think font itself can be an issue. – Makalele Aug 24 '18 at 11:03
  • 2
    Thanks, This helped! Infact, I noticed that having the word "**Neue**" in the family name causes the problem, so simply renaming the family name to "Bebas" was enough. – staticVoidMan Oct 18 '18 at 10:54
  • I can confirm than renaming the font to Bebas is enough. – Skoua Feb 27 '20 at 23:16
4

maybe there is a difference between folder name and font name the solution would be:

  • Print all default fonts names.(without custom fonts)
  • Add custom fonts to project.
  • Print all fonts names.

and after that compare fonts names.

func printFontsNames() {
    let fontFamilyNames = UIFont.familyNames
    for familyName in fontFamilyNames {
        print("------------------------------")
        print("Font Family Name = [\(familyName)]")
        let names = UIFont.fontNames(forFamilyName: familyName )
        print("Font Names = [\(names)]")
    }
}
Mehmet Salih Aslan
  • 241
  • 1
  • 2
  • 10
2

You can actually just go into attributed fonts, click the custom font window. There click the gear in the upper left and click on the option manage fonts. A window should pop up and on the top and there should be a plus sign to allow you to add fonts. Just choose the custom font you downloaded like xyz.tff and then it should be added.

Important to note is that ttf file should be referenced in the p-list as well as in your project directory!

  • Actually, not far off. The font can be installed within the app, but not on your system. For me, installing the fonts into Apple's Font Book corrected the problem. –  May 24 '17 at 15:09
1

TLDR

Create a new user account in Mac OS and see if you are able to have success in the new account BEFORE going through all the steps that I went through below. In hindsight, I probably could have just performed steps 7 and 11 and saved hours of hassle.

Problem

After begrudgingly upgrading to Catalina from Mojave so that I could run the latest and not greatest version of Xcode (11.5), I was no longer able to select a custom font from the font picker for PLAIN text controls within interface builder.

As others have mentioned, attributed text works fine, because it uses the systems font picker instead of the "black box / where did these fonts come from???" picker that comes up when using plain text.

Failed Steps

I tried the following steps with no success:

  1. Re-add the font files to the project in hopes that Xcode would fix the link to the font table that the picker is loading from (still have no idea why there are certain fonts in the picker and where it is getting them from).
  2. Reset the Mac OS font caches using several terminal commands in hopes that the picker is loading the list from a corrupt font cache in the OS
  3. Reset the system fonts by choosing File > Restore Standard Fonts in the Font Book app
  4. Screamed at the computer and cursed Apple for what they have become
  5. Tried installing the fonts in the OS to see if that resolved anything, because I remembered it worked a couple years ago when I ran into something similar.
  6. Searched the internet for any clues and tried virtually everything that seemed reasonable.
  7. Created a brand new simple project ... still could not select a custom font ... ruh oh

Bring in the Big Guns

  1. Cursed myself for not performing a CLEAN install of Catalina and decided to reinstall Catalina from scratch.
  2. Realized that I made a mistake using Time Machine to backup my data before re-installing, because it would not let me bring in just my data files. The Migration Assistant requires the Library data to be imported (option was grayed out when restoring), which I did not want to do ... cursed Apple and myself again because I knew this was gonna bite me in the ... as I suspected there was garbage in the profile that was causing this (I was right ... see below)
  3. Tried to select the font in Xcode while running under the IMPORTED account from Migration Assistant ... SAME PROBLEM ... could not select a custom font

SUCCESS!!!

  1. Created a new user and created a new simple project under that account. BINGO!!! I could select a font now!!! Somehow my user account was corrupted during the upgrade to Catalina
Nimantha
  • 6,405
  • 6
  • 28
  • 69
horistar
  • 11
  • 2
0

It was an old bug since Xcode 3.x:

there is a bug/known issue with IB on XCode 3.x with non-standard fonts and Interface Builder. Custom fonts generally need to be set programatically (via [UIFont fontWithName:])

There are some work around like this with User Defined Runtime Attribute and categories .

Community
  • 1
  • 1
wj2061
  • 6,778
  • 3
  • 36
  • 62
0

I had similar problem

added custom font and also assign it to UILabel all working fine but after a few times later it's wont work as expected.

Trying all solution but nothing work for me. So here is my solution, again going to previous UILabel (already have newly added custom font) select->label->select newly added font. Check other UI controls Font.

now it's working fine.

Hope this help newDevs...

iamVishal16
  • 1,780
  • 18
  • 40
0

This is still a recurring issue for me with Swift 4.2, even without making any changes that would cause it.

Removing the font files from the Xcode project and adding them again fixes the problem (until next time).

alstr
  • 1,358
  • 18
  • 34
0

In my case, a font family was missing in Interface builder, because one of the fonts from that family was not added to the project, but was indicated in the info.plist file.

Generally removing all my custom fonts from the project and adding them again - fixed the issue.

ViktoR
  • 691
  • 9
  • 11