Reputation: 2537
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.
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
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
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.
Happy Coding!!
Upvotes: 3
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:
Upvotes: 3
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.
Upvotes: 0
Reputation: 174
To use custom fonts in application
Check the below link for more reference.
https://stackoverflow.com/a/28843547/9332509
Upvotes: -1