1

I added a custom font called "Quicksand_Dash.otf", "Quicksand-Bold.otf" to an iOS project. I can see it in Interface builder but can't see when I list fonts in code.

  • "Fonts provided by application" and relevant name added to plist file.

  • I checked If font file is in copy bundle resources.

Copy Bundle Resources

Ss 2

ss 3

How I list the font;

for family in UIFont.familyNames {

        let sName: String = family as String
        print("family: \(sName)")

        for name in UIFont.fontNames(forFamilyName: sName) {
            print("name: \(name as String)")
        }
 }

I checked probably every answer in stack overflow but I think I have a different problem.

How To Use Custom Fonts in iPhone SDK

Custom Fonts Not Working

EDIT: If I add a label in storyboard and make its font Quicksand. Font is also listed in code. However, I don't wanna user storyboard. I'm creating controllers in code.

EDIT2: If I delete label in storyboard. It started to not seen again.

This is the same problem I'm facing but I applied the solutions in that post already;

Custom Font only available in Interface Builder

10
  • try to clean your project and run again Commented Apr 9, 2018 at 10:47
  • I did it. I even create a new project but didn't work too :( Commented Apr 9, 2018 at 10:50
  • Are you using this code codewithchris.com/… Commented Apr 9, 2018 at 10:56
  • Yes. I'm using that code. Commented Apr 9, 2018 at 10:57
  • Everything seems right can you share your project ? Commented Apr 9, 2018 at 11:03

4 Answers 4

3

You're going to kick yourself...

In your plist info file, you have:

`Quicksand-Dash.otf`

but the file you added is named:

`Quicksand_Dash.otf`

underscore not hyphen

Either rename your file, or edit the plist entry, and you'll see your font.

Debug console output:

family: Quicksand
name: Quicksand-BoldItalic
name: QuicksandDash-Regular
name: Quicksand-Bold

Here is a plain single-view project that works fine for me - on both Simulator and Device. (I have not added the fonts to OS X, only to my project):

https://github.com/DonMag/Quicksand

Just for setup reference:

enter image description here

enter image description here

Sign up to request clarification or add additional context in comments.

16 Comments

Sorry I forgot to edit screenshot of plist file. Actually, I fixed that but problem is still continue.
Hmmm... I downloaded the fonts (from some site, they appear to be available many places)... I dragged them into the project... made sure Target Membership was selected... add the names to the plist... and only -Bold and -BoldItalic showed up. I changed the name of the file to - instead of _, re-ran (on device), and that's the output I got. Try again with a fresh project - must be something else going on.
Or are you saying it does show up in the font list output, but you can't get it to display in a label?
Maybe this is the problem with xcode it takes some time to add it in project because I have used custom fonts in two another project before and they are showing
Actually I don't understand why they list in code when I add in IB but not If I don't use it in storyboard.
|
3

I also stuck to this issue and given solutions don't work for me. In my case ttf file's "Target Membership" block is uncheck. So when I click on it, the respected ttf font listed in font family list.image attach for reference

Happy Coding!!

Comments

0

From reference of @Donmag answer. I download his example project from GitHub and copy fonts from his project to my project then copy "Fonts provided by application" area from plist to my plist. Interestingly, It copied as "UIAppFonts". However, It started to work now.

SS

Comments

-1

To use custom fonts in application

  • Add fonts to your project folder
  • add it in plist file
  • check if its added in copy bundle resource
  • add font to your font book

Check the below link for more reference.

https://stackoverflow.com/a/28843547/9332509

1 Comment

I already mentioned that I did all the things u said above. :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.