shelll
shelll

Reputation: 3383

iOS custom font in a referenced folder

My custom font from a referenced folder is not in font families and cannot be used. When I use a normal group instead of a referenced folder everything works perfectly. My Info.plist is correct, I have the proper copy bundle resources in the build phases (the referenced folder is there and not every file in it). I also use the proper PostScript name in [UIFont fontWithName] but it just returns nil.

When I check my main bundle, the font file is there in the simulator/device and I can read it without a problem. The only problem is that the UIFont does not see it. When I list font families, my custom font is not there.

This problem occurs only when I have my custom font in a referenced folder or in a custom bundle (which is also a referenced folder). When I put the font in a normal group everything works. I tried cleaning the project, uninstalling the app and also resetting the iphone simulator. This same problem happens when I build from Xcode 4.6 and Appcode 2.1. I am building against iOS 6.1 SDK.

I went through all the tips and tricks about using custom fonts in iOS and the only difference is the referenced folder. I want my resources in a referenced folder (or a custom bundle) because I create resources (shader/textures/...) in other programs and I just want to copy them to the folder and not add them one-by-one to Xcode.

What could be wrong with my approach? Or is this a known bug/limit of the build system?

Upvotes: 2

Views: 828

Answers (2)

shelll
shelll

Reputation: 3383

I fount the solution when solving another problem (missing icons, when moved them into a referenced folder/custom bundle).

The solution to this problem is to use the whole path to the custom fonts in the plist file (the whole relative path within the project's directory). In my case it looks like this:

<key>UIAppFonts</key>
<array>
    <string>mybundle.bundle/fonts/OpenSans-Regular.ttf</string>
    <string>mybundle.bundle/fonts/OpenSans-Light.ttf</string>
</array>

When using Xcode's "graphical" representation of the plist, just enter the whole path with the file name there.

When using other resources from a referenced folder/custom bundle e.g. images for button icons and setting them in the code, also use the whole path and not just the image's name e.g.

[UIImage imageNamed:@"mybundle.bundle/images/cancel.png"]

instead of just

[UIImage imageNamed:@"cancel.png"]

Upvotes: 4

denvdancsk
denvdancsk

Reputation: 3053

It's a limitation of Xcode. I had the same problem not too long ago. I am hoping that eventually XCode comes out with a packaging or collection option that repackages your code in pretty folders the same way cocoa pods does but for now we're stuck.

Upvotes: 0

Related Questions