This is a topic that looks like many others have struggled with. I'm trying to add the 'Impact' font to my iOS project. To do so, I perform the following steps:
1. Add the Impact.ttf file to my project.
2. Ensure that the Impact.ttf file is in fact added to the project Target.
3. Check 'Copy Bundle with Resources' in the target Build Phases and make sure the Impact.ttf file is included .
4. In My-Project-Name-Info.plist, I added the "Fonts provided by application" option and set Impact.ttf as item 0 in the array.
5. Open the font file with Font Book and make sure I'm referencing the font by the correct name. In this case, Impact is the correct name.
I used the following code snipped to see all available fonts in the project, and 'Impact' is not one of them:
for (NSString *family in [UIFont familyNames]) {
NSLog(#"%#", family);
for (NSString *name in [UIFont fontNamesForFamilyName:family]) {
NSLog(#" %#", name);
}
}
When inspecting the value of UIFont in the following snippet, I get nil.
UIFont *impactFont = [UIFont fontWithName:#"Impact" size:36.0f];
I've quadruple checked all spellings and gone through each step multiple times. I've also used the following resources (and many more) to troubleshoot the problem.
Custom font in iOS not working
iOS custom font robot bold not working
Common mistakes with adding custom fonts to your iOS app
One item to note: If I open Impact.ttf with font book, it says that the font is not installed. I click to install the font, and get a warning that there are duplicate Impact fonts installed. To fix this warning, I click 'Resolve duplicates automatically' and the font shows as installed. However, if I open the file again, the font shows as not installed. I'm not sure if having the font installed in Font Book is necessary for it to correctly be recognized in my project .
Thank you very much for your help! I know this question has been asked multiple times, but I feel like I've exhausted all resources and links here on SO and other sites.
Maybe this is not the answer you want, but is a solution you could use to move on.
That is what i use on my projects, simple and useful https://github.com/deni2s/IBCustomFonts
Hope you can find a better solution!
Related
My App will be used on iOS, I have Windows and Android versions, but I am not too concerned with getting the custom font to work for those platforms. Mainly IOS.
I know how to add the .ttf file to my Resources folder, and set it to Copy Always, I also update the IOS file info.plist and add a string array with name 'Fonts provided by application' and value 'Cardinal.ttf'
What I am not clear on is how to call the Font Family in my Cross Platform code. I know I do something like
labelName.Font = UI.Font( "Cardinal" )
However this will not work in Cross Platform because the UI namespace is not available.
Any help here?
Something with Device.OnPlatform( ...
Thanks to #Gusman above! You simply specify the FontFamily as a string with the value of the Font name. As long as you added the ttf file to resources and updated the info.plist file correctly, it will load the Font on App startup and the call to
FontFamily="Cardinal"
will work fine. Cheers!!!
I am wanting to use Helvetica Neue Ultra Light in my Watchkit app. I have followed all of the instructions for adding a custom font (added to Extension bundle and added in Info.plist for Extension and Watchkit app), but NOTHING is working and it will never get used.
Really strange thing is, other ttf fonts that I have added DO work, it seems to just be some strange issue with Helvetica.
Where is Helvetica, and why can't I add it?
Edit: To clear things up and prevent what people think might be obvious answers.
Watchkit only includes the system font (San Francisco), it doesn't
expose all of the fonts that iOS has. (Ref:
devforums.apple.com/message/1096179#1096179) THIS is why I am trying
to include Helvetica.
Option 1
I had the same issue. I fixed it by including the - character between the font name and the name of its weight. In some ways, Xcode could recognize the font.
Try changing HelveticaNeueUltraLight.ttf into HelveticaNeue-UltraLight.ttf wherever possible (info.plist file and in the project folder).
Option 2
Open up the FontBook that comes included within your Mac. Install the font if you haven't already and look closely at the PostScript name of the font. If it differs from the name you are currently using in Xcode, then change it.
Option 3
If you can't still get this working, download the same font from another source.
I have two fonts with the same name (the two fonts have different ascender properties). How can I include both fonts in my project and use them? I am unable to figure out how to change the name of one of the fonts without installing Font Forge, which seems like a day long project. Any ideas?
There are some font files in my code repo for the font Nubian and Nubian-Alt. They are licensed and paid for and they need to be used. However I cannot use this font in iOS, and I cannot open the font with Font Book even though the font previews OK in Finder and is identified as a Truetype Font.
I started by trying to add Nubian-Medium to the iOS app - using the key "Fonts provided by application" in the app's Info.plist. The font did not appear in the list generated using:
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"%#", fontName);
}
}
I checked the Target's "Copy Bundle Resources" Build Phase, saw the font had been added to the list.
I tried adding another font I have used in another app, "chess-merida-unicode.ttf", to check I was adding a font correctly - I copied it to the app and added it to the array of fonts provided by application, saw it appear in the "Copy Bundle Resources" list, it was reported as available using the above code snippet.
Next I took a look at the font in OS X - double-clicking does open Font Book but the font is not opened or added. When I tried to drag all the Nubian fonts into Font Book as a new collection it reported problems with all the files, specifically in tables contained within the font file.
Selecting all fonts and then choosing proceed did nothing.
I downloaded a trial of a third-party app named Font Agent Pro and it also could not load these fonts.
I found a sketchy site called fonts.com and downloaded another Nubian-Medium ("ufonts.com_nubian-medium_1_.ttf") - Xcode was able to recognise that file.
I checked the permissions on these files and made sure they were rw for all, no change.
At this point you would suspect the files are just broken or corrupted but they are in use on a web page (that is also part of the project) and that works fine. What other steps could I take? What can I do to get these files added to the iOS project? If there are certain kinds of TTF that cannot be used in an iOS project, how can I check whether these are that kind?
Step 1: Download Nubian Font From : http://www.fontpalace.com/font-download/Nubian-Thin/
Step 2: Add Font .ttf File in your project
Step 3: Register your Font With Application, set Fonts provided by application key in your info.plist file, See the ScreenShot for details.
Step 4: Create a Label and Assign the font to it ,as following
UILabel *lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 50)];
[lbl setText:#"I am Nubian-Thin"];
[lbl setFont:[UIFont fontWithName:#"Nubian-Thin" size:26.0f]];
[self.view addSubview:lbl];
The answer seems to be that these fonts were "web" fonts. I don't know how to tell the difference, given a TTF file that looks just like a "desktop" font. Learning how to do this was kind of the aim of the question.
Practically speaking, digging out an old archive from someone's hard drive discovered another archive with TTF fonts that worked. These fonts still had 8.3 filenames and were all created as members of their own font family (so Nubian-Medium and Nubian-MediumItalic were in no way related). I renamed them, then ran them through the trial of RoboFonts to correct the family relationship. This resulted in TTFs all in the Nubian family. And then found a weird issue where a UILabel created with this font came with a 1-pixel horizontal rule at the top of the frame. Going through the process again but choosing to generate OTF output got rid of the line.
Fonts are easy, except when they aren't, then they are really hard.
Following the instructions here, I'm trying to use custom fonts on my game. The custom font works okay in iOS device but not on the android device I'm testing on. I've made sure to include the font file (.ttf) on my project folder and I'm using this to set the font:
if(system.getInfo("platformName") == "Android") then
label = display.newText("text", 100, 100, customfonthere, 38)
end
However, when I run the game on the device, the custom font doesn't work. Is there something I might be missing here? I've also tried the font name with and without the file extension.
UPDATE: Actually, never mind. I guess my font file was damaged somehow. I just deleted it on the project folder and copied it from one of my backup files.
For everyone else who encounter problems with using custom fonts in Corona, try deleting the font file and redownloading it from wherever you got the font file or if you have a backup of the font file somewhere, just copy it back to your project folder. My font file was damaged so when I deleted it and added it again, it worked.
Follow the instructions from here. If the font doesn't show on your simulator, don't panic like I did. It simply means the font isn't installed in your workstation but rest assured, it will work on the device.
Then just use the font like you would use any system fonts in corona. You don't have to put the file extension (ttf or otf) for android devices. At least that's how it is for mine.