I have used a custom font in my previous app.
The file name was "ProximaNova-Regular.otf" and to load the font I just used...
[UIFont fontWithName:@"ProximaNova-Regular" size:20];
This worked perfectly.
Now in this new app I have three font files...
Dude_Willie.otf Impact handsean.ttf
But I'm not sure how to load these.
I have tried
[UIFont fontWithName:<the file name> size:20];
But this just falls back to using Helvetica.
How can I find what name to use?
Step 1: Click into the windows start/home icon on the bottom left corner of your desktop screen, and type Control Panel. Click the control panel app. Step 2: Find Appearance and Personalization and select it. Step 3: Click Fonts.
Right click on the TTF -> Get Info
"Full Name" is what you're looking for.
That's what worked for me with TTFs.
Edit:
I just used a font that had a different name from the "Full Name" in Get Info.
For the compilation of this answer, If the quick check above doesn't work, run this code in your project:
for (NSString *fontFamilyName in [UIFont familyNames]) { for (NSString *fontName in [UIFont fontNamesForFamilyName:fontFamilyName]) { NSLog(@"Family: %@ Font: %@", fontFamilyName, fontName); } }
And search for the correct name of the font you want to use.
Swift 3.0 code:
for fontFamilyName in UIFont.familyNames{ for fontName in UIFont.fontNames(forFamilyName: fontFamilyName){ print("Family: \(fontFamilyName) Font: \(fontName)") } }
Follow these four easy steps to add and use a new font in your iOS app:
UIAppFonts
array (plain text for this one is 'Fonts provided by application')//Swift
for family: String in UIFont.familyNames { print("\(family)") for names: String in UIFont.fontNames(forFamilyName: family) { print("== \(names)") } }
//Objective-c
for(NSString *fontfamilyname in [UIFont familyNames]) { NSLog(@"family:'%@'",fontfamilyname); for(NSString *fontName in [UIFont fontNamesForFamilyName:fontfamilyname]) { NSLog(@"\tfont:'%@'",fontName); } NSLog(@"-------------"); }
UIFont *myNewFont = [UIFont fontWithName:@"font_name_from_debug_output" size:20]
and you should be in business!If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With