Labels are not changing to custom font - objective-c

I am trying to set a label to a custom font with the following code.
cell.lblDataum.font = [UIFont fontWithName:#"Homenaje_Regular" size:10.0];
I'v added this font in my .plist.
<key>UIAppFonts</key>
<array>
<string>Homenaje_Regular.ttf</string>
</array>
But still no succes. Can anybody help me?
Kind regards

Are you sure you added you Homenaje_Regular.ttf file to your Xcode project and added it to your target's Copy File Build Rule (checkbox is checked next to the target name in the Inspector Panel?) so that the TTF file is copied into the application bundle on compilation.
But more likely, the name of the font is probably not #"Homenaje_Regular". You have to use the real font name as a parameter for fontWithName:and that's not always the same as the file name.
In your case, the real name of your font is probably "Homenaje-Regular" or just "Homenaje" and not "Homenaje_Regular".
You can have the real name of the font by opening your font in FontBook on your Mac and simply press Cmd-I to get that information.
You can also list by code in your iOS app all the fonts available to make sure your font is correctly detected by your app and pick up the right name of your custom font to use with fontWithName: :
for ( NSString *familyName in [UIFont familyNames] )
{
NSLog(#"=== Family %# ===", familyName);
NSLog(#"Names = %#", [UIFont fontNamesForFamilyName:familyName]);
}

I believe, the name of the font is Homenaje-Regular, not the file name.

Related

Custom font doesn't work

I'm trying to add a font into my project to use in a label but it just don't work. Here is what I'm doing:
I copy the font file into my project resources.
Set my plist file with the array key UIAppFonts.
Add my font's name Kingashandwriting.ttf (the real name with the extension
, not the file name) into the array.
Set up my font in the code: UIFont *font= [UIFont fontWithName:#"Kingashandwriting" size:15];
Set it into my label: [self.myLabel setFont:font];
myLabel is an IBOutlet that is linked with a label in interface builder.
I'm using Xcode 4.3.3
Am i missing something?
I remember that I ran into this same problem when implementing custom fonts into my application. I thought that I had the official name right but it was giving me problems.
My advice is to open up the file in font book and look at the top of the window and see what that name says. Then format it exactly how you see it in your fontWithName: method.
Here's an image of what you're looking for:
http://i.stack.imgur.com/uOZy6.png
Then your font method would look like this (based on the font in the image):
UIFont *font= [UIFont fontWithName:#"BankGothic Lt BT" size:15];
For further information, in my application my file is named bankgthl.ttf and I have that file name added into my plist array. But when I am setting the font in my code I call it the same as above using the name seen in font book and it is all working fine.

Adding custom font to project, programmatically add item to plist

I want to add some font to my project. I have directory in my project contains fonts. So i can access to my font by:
NSString* path = [[NSBundle mainBundle] pathForResource:#"res_name" ofType:#"res_type" inDirectory:#"res_directory"];
But how to add it to my project so i will be able to call it like this:
[UIFont fontWithName:#"Font-Name" size:14.0]
I'm only interest how to do this programmatically I'm assume that I have to add it to my plist, but can i do this programmatically?
I understand o have to use a in plist:
<key>UIAppFonts</key>
<array>
<string>swellfont.ttf</string>
</array>
But i cannot do this in Xcode manually. I want to check what fonts i included in my project in resource directory and add them programmatically from code.
The UIAppFonts key in Info.plist.
You can take a look at the Core Text Font Manager to see if registering fonts by URL make them loadable with +[UIFont fontWithName:].

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

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.

iPhone Development: how to use custom fonts?

I used a special font in my photoshop design,
is it possible to use these fonts natively in the iphone app? or
do I need to convert them into an image first?
If this is the only way to do it, what do you do with dynamic text?
Copy your font file into Resources
In your application .plist create (if it's exist just create a row) a row called "Fonts provided by application" and then in "item 0" copy your font name for example "Ciutadella-Bold.otf" (if there are some spaces in font name, rename it and for example replace all spaces to minus '-')
Then you can define this font in your application:
UIFont *CiutadellaBold = [UIFont fontWithName:#"Ciutadella-Bold" size:17.0f];
And use in for instance in uiLabel:
[uiLabel setFont:CiutadellaBold];
UIFont *font = [UIFont fontWithName:#"MyFont" size:20];
[label setFont:font];
Where "MyFont" would be a TrueType or OpenType file in your project (sans the file extension), and label would be an instance of UILabel.
Yes it is possible with iOS 3.2 and later. You need to have the fonts file, I forget what formats exactly. Add the font file as a resource to your project then add the names of the fonts in the applications info.plist in an array under the raw key 'UIAppFonts' or under the friendly key 'Fonts provided by application'.
Here's a sample application that you can look at - https://files.me.com/tobiasoleary/ey08n1. It prints out the all the fonts accessible to the application. Two fonts have been added Flames and Firestarter.
This is by far the easiest way to add custom fonts to application. If you need to support custom fonts for iOS before 4.0 see http://github.com/zynga/FontLabel/tree/master
This question has been asked before here: Can I embed a custom font in an iPhone application?.
Note :
The parameter of “fontWithName” must be the real name of the font, not the name of the file. If you open your ttf file with the Mac Font Book, you will directly see its name on top of the window.

Custom font for iPad - iOS 3.2 isn't working

I'm building an iPad-Only application. I need to use a custom font with some labels, so I added them to my project. They appear in my application target for "Copy Bundle Resources". I also added their names to my App's -Info.plist file:
<key>UIAppFonts</key>
<array>
<string>font1.ttf</string>
<string>font2.ttf</string>
<string>font3.ttf</string>
<string>font4.ttf</string>
</array>
Even so, when I try to set the font of my labels, it seems to just use the default. I haven't been able to figure out how to overcome this issue. Any assistance would be greatly appreciated.
Edit:
- (void)debug {
NSLog(#"fonts: %#", [UIFont familyNames]);
UIFont *f1 = [UIFont fontWithName:#"Helvetica" size:20];
UIFont *f2 = [UIFont fontWithName:#"font1" size:5];
NSLog(#"f1:%# f2:%#", f1, f2);
}
And the output: http://pastie.org/1323195
How are you setting the font?
You need to use it as follows....
UIFont *myCustomFont = [UIFont fontWithName:#"font1" size:30];
The solution ended up being to use a different font. I opened the font with FontForge and got this warning:
This font is marked with an FSType of 2 (Restricted License). That means it is not editable without the permission of the legal owner.
This seems to be the cause of my issues. I downloaded a free version of the font I was trying to use (luckily it was available for free) and everything started working perfectly.