Emre Önder
Emre Önder

Reputation: 2537

Custom font seen in Interface builder but not in code in iOS project

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.

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

Upvotes: 1

Views: 1395

Answers (4)

bittu
bittu

Reputation: 713

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!!

Upvotes: 3

DonMag
DonMag

Reputation: 77433

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

Upvotes: 3

Emre Önder
Emre Önder

Reputation: 2537

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

Upvotes: 0

Krishna Maru
Krishna Maru

Reputation: 174

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

Upvotes: -1

Related Questions