I am developing for macOS and I would like to use a custom TTF font with SKLabelNode in my SpriteKit project.
I did search the web how to do it and every place I can find describe the following steps:
Add the font to your app bundle
Add the "Application fonts resource path" key to Info.plist with
"Fonts" as the value
Add the "Fonts provided by application" key to Info.plist and add name of the font file
Create a Copy build phase with "Resources" as the Destination and
"Fonts" as the Subpath
Drag/Drop the font to the Copy build phase
In Finder right-click on the font file and select the "Get Info" menu option.
From the "Full Name" field, copy the font's name
I have done everything from the list above and I try to set the font inside the didMove() method programatically like so:
titleLabel = self.childNode(withName: "TitleLabel") as! SKLabelNode
titleLabel.fontName = "Lobster Regular"
However, when I run it, I get the error "Lobster Regular" font is not found. I double checked and this is the name of the font. I also tried to use the file name but that also did not worked.
I did also follow the official documentation.
The problem is however, the documentation suggest that after adding the font to the Xcode project and include the keys in info.plist, I should be able to assign the font to labels using interface builder. But in my case, the font does not show up inside interface builder.
If I add the font to Font Book, it works, I can use it both programatically and inside interface builder but I would like to include the font with my app/game instead.
What am I missing? Is there any other properties in Xcode I should check?
Thank you.
It seems in my case the solution was to set the "Application fonts resource path" key to an empty string, just leave it blank the value field to automatically pick up all fonts I have included with the project. Entering a . as value also seems to work and able to set the font programatically this way.
Related
Now that Apple has taken away the Plist, naturally it has changed the way we add custom fonts to our app. Before we just added the file to our bundle and set a property for it and our plist and viola..
Now I am curious.. can it be done without adding a custom plist as shown here or is that the only option?
drag and drop your font-file into the project (make sure you hit copy if needed and check the target box)
choose Project -> Targets -> Info -> Custom iOS Target Properties and klick the small + icon under the "key" property. Start typing "Fonts provided by application"
enter the full font-filename inside this property-list
now you can use the font by its name
(Bonus: if you have trouble to find the font name, you can print all available fonts with [see detail explanation for this at code with chris ]:
for family: String in UIFont.familyNames
{
print(family)
for names: String in UIFont.fontNames(forFamilyName: family)
{
print("== \(names)")
}
}
You can add font files name same as you add in project directory info.plist
Just go to
Project -> Targets -> Info -> Custom iOS Target Properties
Add your all permission or file here.
Need to add Ubuntu Font through .xib , i Mean it should be like in the list for Example Font:Custom Family:Helvetica Style:Regular , Family Should be 'Ubuntu'
OR
Can We Change the system Default Font To Ubuntu.
This behavior is not possible via XIB
If you want to add your custom font through xib --> font property means, it is not possible. But, if you want a label or textfield or etc., with your custom font means we achieve this by sub-classing the respective control i.e, overriding the awakeFromNib. And you need to add your custom font in the .plist file of your project under the key "Fonts provided by application". Like this..
I'm trying to use this font in my app. I've added it to the plist and to the project, but for some reason it is not loading on the label. I've tried to verify the font in the project with:
NSLog(#"DK Crayon Crumble: %#",
[UIFont fontNamesForFamilyName:#"DK Crayon Crumble"]);
But I'm getting this output:
DK Crayon Crumble: ( )
I found the problem. For some reason Xcode it was not copying the font file to the bundle package.
The convention with the built-in fonts (you can select them in Interface Builder) is that you eliminate the spaces and add the attributes after a hyphen, such as
#"HelveticaNeue-Bold"
for Helvetica Neue, Bold.
I don't know the exact name of your font but if you follow this scheme, it should work.
Some times the fonts are visible in the project file but are not actually
added to the target to do so
click on the project's name -> click on target -> Build Phases, go to
'Copy Bundle Ressources', if the concerned font(.ttf extension) file is not there add it to the list.
Clean your Project and run you should be able to see the font.
Maybe the problem is that the name of font is with space. Remove spaces, in real file name, add it again to your plist and try again with code:
[UIFont fontNamesForFamilyName:#"DKCrayonCrumble"];
This link help you to set font:
set custom font
i need to use corbel and caliber font in textview , textfield and label in my new application. I have searched for it in google but i did not got any solutions . Can any one please help me. Thanks in advance.
Follow these steps:
1) Add desired fonts to Xcode as resource.
2) Open info.plist file. Now create a key called UIAppFonts and make it an array. Add the filename of the font as a value.
<key>UIAppFonts</key>
<array>
<string>corbel.ttf</string>
</array>
3) Save info.plist FILE.
4) To use the font in your application add this line.
[UIFont fontWithName:#"corbel" size:32.0]
Courtesy :
Can I embed a custom font in an iPhone application?
CUSTOM FONTS IN IOS.
P.S. But to determine the exact name of font put temporary line of code as even small case sensitivity might cause a problem loading fonts.
NSLog(#"%#",[UIFont familyNames]);
This will print names of all the fonts on the device. Find the one that matches your font.Whatever the font name you get use it in the line in Step 4.
Courtesy: How do I include a font with my iPhone application?
You can add custom fonts to Xcode, I think this article can help you out doing so. I also found this video. As for the caliber and corbel files, a quick search in google will get what you want: corbel caliber tff.
Install same font in Mac OSX and try to find same font name in textedit application.
type exact spelling (with case sensitivity) in Xcode.
some time it happens font file name is different and we type it differently.
put the exect file name in plist file... but use the installed font name in application (Xcode.)
I've already seen this post:
Can I embed a custom font in an iPhone application?
which is helpful, but I'd love to simply load the font via:
UIFont* font = [UIFont fontWithName:#"Harrowprint" size:20];
Some people have reported this possible but it's not working for me. Can someone confirm how to bundle a custom font with an iphone app?
Also, in the aforementioned post, one answer notes: The "name" of the font is not necessarily the filename.
How do I determine the "name" of the font that would be recognized by UIFont? It's possible i'm not using the correct name.
There are several steps you need to take:
1) Make sure you have the rights to distribute the font. Most fonts -- even free ones -- do not allow you to distribute them. Putting them in your app most likely consitutes 'distribution' and would be considered illegal.
2) Copy the font to your Resources folder in your app. Make sure it's in your Copy Files build phase.
3) Add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension)
4) Get the 'name' of the font by putting in a temporary line of code:
NSLog(#"%#",[UIFont familyNames]);
Build and run the app. This will print to the Console the family names of all the fonts on the device. Find the one that matches your font.
You can then use that font name in the fontWithName: method.
To add onto August's answer above, you need to add a "Fonts provided by application" key to the plist file, and add the complete file name of the font (including extension). Then the font will appear in the family printout and you can use that name to set the font.