Custom fonts on iOS app - working in Simulator but not iPad - objective-c

Encountering a weird problem here. I'm developing a game for my school project (non-commercial), and I'm using a custom font Black Chancery (free under GNU GPL). I followed the instructions from multiple sources, which includes:
Add the font to the project (TTF).
Modify app-Info.plist to add the font to it ("Fonts provided by application").
Using [UIFont fontWithName:#"BlackChancery" size:30] when the font is needed.
I could get the font displayed in the Simulator, however when I load it into my iPad, the default system font is used. I'm pretty sure there isn't a problem with the font itself as it displays in the simulator, and I've used FontForge to open the font without any warnings (following from This Question).
Any help is greatly appreciated. Thanks! :)

I can only guess as you haven't posted the contents of your plist or a directory listing of the bundle, but many cases of "resource works on the simulator but not on the device" are caused by the fact that the OS X filesystem is normally configured to be case-insensitive while the filesystem on the device is case sensitive. For example, if your file is named "BlackChancery.TTF" and your plist refers to it as "BlackChancery.ttf", it will be found on the simulator but not on the device.

I was having problem with font not recognizing, I fixed it by checking the correct name of the font by checking info of the font file by Get Info option. In my case the file name was written xyzfont.ttf but actually it was XyzFont.TTF in the info, i replaced and it worked.
Hope, it helps someone.
Another Way
I have come across one more way of finding the correct name, is by installing the font in the FontBook..
Just open FontBook from Finder and select User now from File->Add Fonts select the font you want to add into your application, after little processing the FontBook will show the Font listed in with the Correct name, use the name in the FontBook ignoring the actual ttf file name you have imported or, added to plist.. It should work..

I had the same problem which was resolved with a slight variation on iphonc's solution. The case sensitivity was directly related to the file extension. The problem was associated with my font file named: Choc.TTF
I had to remove the reference to the file in xCode 4.1
Rename the file to Choc.ttf (note lower case file extension)
Add the reference back into xCode
Perform a clean and re-build for the device
Conclusion (in my particular case):
Case sensitivity applies not JUST to the file name, but to the file extension as well (i.e. iOS device appears to tolerate only lower case).

My answer is different from all the rest. I had a problem because the font was all one word and lowercase "compassnormal.ttf" and the name in the file was Compass. So, my code was:
[UIFont fontWithName:#"Compass" size:24]]
Bundle Resource said:
compassnormal.ttf
~info.plist said:
compassnormal.ttf
None of this worked until I changed the actual filename to match it's official name in fontbook.
deleted all references from Bundle Resources and ~info.plist;
added font with updated name to Bundle Resources;
updated plist with new name;
tested in simulator and on device, Voila!

I have also experienced a problem with fonts containing the dash (-) character. Remove that character from your font names and try with that.
So your font named Gotham-Black.ttf should be named GothamBlack.ttf

Also check that your fonts are not zero bytes. I had this same issue and it turned out that my font files had emptied themselves at some stage. Probably when rearranging them in XCode and AppCode.

You have to use the real font name in the [UIFont fontWithName:#"... method! Not the ttf filename!!!
This real name is mostly far away from the filename. Just open the rtf in the Mac font utility. In the header you see the font family!!! Only the family!!! if you now use
NSArray *fontNames = [UIFont fontNamesForFamilyName:#"MyFontNameFamily"];
NSLog(#"%#", fontNames);
in your code, you get the real real real name in the console ;-)
But in the plist entry you still need the (case sensitive) filename!!!

I have the same issue on Xcode 6. My file name was My Font.ttf, it doesn't work. I manage to make it works when I rename it to My Font.TTF, just change the file extension to uppercase.

Related

Icons, Asset Catalog and Info.plist confusion

I have an app that started life for iOS 5 and has been updated ever since. For iOS 7 I have switched over to using an Asset Catalog for all the resources, which is nice and appears to work well. However, when I try to submit to Apple I get validation errors:
Invalid Image Path - No image found at the path referenced under key 'CFBundleIconFiles': 'Icon#2x.png'
I get the same error for the other icons, too. These icons do appear in the Asset Catalog and the names -- right down to the case -- match exactly as far as I can tell. The Asset Catalog is in the "Copy Bundle Resources" and all the resources appear in the right place when I run the app on both my iPhone and iPad (in iOS 7) and in the Simulator for iOS 6.
I have updated the app to use the minimum deployment target of iOS 6.
So, how do I successfully submit my update to Apple? Do I need the references in the Info.plist? Are there any other settings that I should check? Is the warning spurious and something that I should ignore (after raising a Radar)?
When an asset catalog is compiled for iOS 6 and lower, the images are put in the root of the app bundle, as if you were just copying them the old way. When this happens, Apple names the images according to the asset name, rather than the filename, which means we can still use +[UIImage imageNamed:] to get the assets on iOS 6 and lower.
This is true for the App Icon asset, when we have the following icons set in our asset catalog:
They become compiled like so:
As iOS 6 is still iOS 6, these files must be referenced in the Info.plist, otherwise the existing system wouldn't work. Looking in the compiled Info.plist for this test app, you see that Xcode has added CFBundleIconFiles for us and so we don't need to.
I have uploaded the test project I used to github.com/danielctull-tests/AssetTest.
Okay, so here is what I ended up doing. I'm not 100% sure it's correct but I thought that it was worth sharing.
I removed CFBundleIconFile, which I don't think is used in iOS 6 and above
I used the asset name rather than the icon filename in CFBundleIconFiles
I'm not clear what the proper names are so, for the sake of clarity: by icon filename I mean the name visible in the Attribute Inspector of the Asset Catalog when the icon is selected; and by asset name I mean AppIcon, which refers to seven actual icons in my case.
This both passes Apple's validation step and appears to look okay. I don't currently have an iOS 6 device but it displays correctly in the Simulator.
I had also a lot of Problems on this matter - I was constantly getting the error with the missing CFBundleIconName and that my Icons where not found. So here is my story, maybe it will be of help for somebody. By the way, I am using Visual Studio with Xamarin.
Add an Asset Catalogue to your Project with AppIcons (the actual name of the asset is not important but just that it is for the application icons). Add all of the necessary icon sizes. For the 'App Store' icon I have added an icon without a # in the name as someone in the forums suggested, but I am not sure, if it is 100% necessary. For generating the different icon sizes there are a lot of Websites and tools that can do that for you and you just need to provide the 1024x1024 one. They will generate the rest.
In the Info.plist under 'Visual Assets' and then 'App Icons' set the source to the asset that you have just created.
Now check your Info.plist. Do not open it with an external Editor, because all of your changes will be overwritten once you build your project. Do the following - right mouse click on the Info.plist in the Solution Explorer then select Open With -> Generic PList Editor.
Check that you have the following entries:
-Property = CFBundleIconName, Type = String. Value = Assets.xcassets/AppIcons.appiconset
-Property = XSAppIconAssets, Type = String. Value = Assets.xcassets/AppIcons.appiconset
Note that Visual Studio automatically adds, when it adds something altogether, 'Resources/Assets.xcassets/AppIcons.appiconset' as the Value. But in my case the Asset Catalog was created outside of the Resources folder and therefore, my icons where not found. So, check where your assets folder was created.
CFBundleIconFiles was not needed, because Apple uses the Asset Catalog instead now.
I hope that I was of some help :)

Custom fonts aren't working

That we can use a custom font within my app is not a secret, but I can't reach this and wonder why.
Of course I searched the whole web for this problem but nowhere found something similar, so this is why I finally need to ask this.
What I'm trying: I'm on my way to create a small game and draw always my whole gamefield. Good, this works just fine with the default fonts, but doesn't with my custom font...
I added my .ttf-Font (I tried two different) to my project using drag and drop and copy it to my project folder. Next I added MyFontXY.ttf to my Info.plist using UIAppFonts and an array.
Next I tried to use it with [UIFont fontWithName:#"MyFontXY.ttf" size:12] - ok fine, doesn't work. I searched for the real name of the font and tried [UIFont fontWithName:#"My Font XY" size12] but it doesn't work, too.
So I tried several things after this like cleaning, reimport, change the name, ... but nothing happened. I also used NSLog(#"%#",[UIFont fontFamilies]) to find out which fonts are available, but my font wasn't there.
I also checked if the numbers were available with this font and they are, so I excluded a lot of possibilities now.
What can I do now? Does someone has this problem too?
You need to add the fonts to your target, for instance by manually adding them in the "Copy Bundle Resources" phase of your target

-HD image file not found?

Why am I getting
cocos2d: CCFileUtils: Warning HD file not found: META-hd.png
If I definitely have META-hd.png file in my project?
What I am doing is running my .tmx tilemap. The map uses a tileset that searches for "META.png" (without -hd suffix since I am expecting cocos2d to automatically put it on).
I've found the problem. I only do have -hd versions of my files. But I don't have "non-hd" versions. And for some reason, CCFileUtils will throw me errors when I don't have both types in my project.
Verify that the image is part of the app's target. If it was included as part of a group, and say there was a duplicate on file 10 of 25, the copy stops and files 1-9 are NOT tagged as part of the target. You have to go back and sweep the floor by hand.
In Xcode 4 show the assistant editor, and click the resource in the navigator. The target membership will be shown. If your app is not checked, click on that and voilà, the file will now be found.
In rare cases, i have had to clean the target and recompile to make this effective.
If I understand correctly you will have to have a -hd version of the tilemap as well: meta.tmx and meta-hd.tmx.
Also be sure that your image file is named META-hd.png and not META-HD.png and both images use the same case: META.png and META-hd.png. The iPhone file system is case sensitive (not the iOS Simulator though).

Adding custom fonts to my iphone application

I want to use a custom font in my iPhone app. After doing some research I found that you can add a custom font to your package. So I copied the font, which is digreadout2.ttf to my app folder and added a key in the .plist file. using the exact filename including the extension.
I then create the UIFont object and assign it to the font property of my UILabel. Now the problem is that when I run my app it gives me an error saying <Error>: FT_Open_Face failed: error 2.
If anyone has any suggestions of what I can try it will be very helpful.
Thanks for the response, I found the error. Basically what happened was that the file I used for my font had a white space in the file name. So when I tried to load it in the plist file it gave the error of file not found, once I removed the space out of the filename everything worked perfecty.
Error 2 in Free Type is FT_ERR_BADLABEL which I guess is the same as ENOENT - No such file or directory. Maybe you are using UIFont with the filename instead the font name. See Certain fonts not showing up?

<Error>: FT_Open_Face failed: error 85

I am trying to install a custom font into my iPhone application. When I add the 'Fonts provided by application’ key into my info.plist file I get the following error ': FT_Open_Face failed: error 85.’
I am not sure what the problem is as I have successfully been able to use custom fonts in the past.
Any help will be appreciated.
If you leave the first element in your font array in the plist (index 0) blank, you will get this error.
PostScript fonts cannot be used with UIFont directly. You can use them only with CoreText or CATextLayer.
This can occur if the font in question is a Font Suitcase format. Open your application package, and if the font .ttf file shows a size of "Zero bytes", it's probably a font suitcase.
Files of this type can be converted using Fondu.
When running Fondu, I had to specify not just the suitcase file, but the resource fork inside it:
fondu mysuitcasefont.ttf/..namedfork/rsrc
This will extract any fonts in the suitcase to the current directory. It is these extracted files you will want to include in your iOS project and reference from the .plist.
I received this error when using a .ttf font. I was able to correct it by removing the file extension from the filename in (a) the resource in xcode and (b) the "Fonts provided by application" array in the .plist file.
Hopefully this will help.
I was trying to use Google Signika font on my App, and got the exact issue.
I solve the issue by using the .otf version of the font
Accepted answer is totally wrong and unnecessary. Probably you made a mistake when writing your font name.
Thats rules for that.
First Step : Write font name before .ttf extension. Example: For FFFTusj.ttf => FFFTusj
Second Step : Write - and after font style. Example: Bold or Medium etc. Example: #"FFFTusj-Bold"
And also dont forget add your font file to your project.
Check this link:
http://www.bycoder.com/post/2013/03/28/XCode-Custom-font-doesnt-work
If your font is REGULAR dont write -Regular at end of font name.