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.
Related
Hi I am using below code to use custom font style for label text. I've installed it and work fine but the problem is that the size of text does not change. I've tried more times with different sizes. I don't know what should do
self.saveButton_label.text = NSLocalizedString(#"Saved", nil);
self.saveButton_label.font = [UIFont fontWithName:#"Helvetica Neue LT Pro" size: 13.0];
I believe the issue lies with one of the steps you need to take when adding a custom font to your project, you probably are not noticing the difference because Helvetica Neue is also the default font, which I believe is used if you were to assign nil to UILabel as the font.
I suggest following this guide, I've used it as a checklist myself when using custom fonts and it has worked, especially take not of the naming, the name you have to use in code might not be the one you see in FontBook or when using Preview on the font.
Try this code, In your code you are missing "-" with font name.
self.saveButton_label.text = #"Saved";
[self.saveButton_label setFont:[UIFont fontWithName:#"Helvetica-Neue-LT-Pro size:13.0f]];
also you can use below fonts.
HelveticaNeueLTPro-MdCn
HelveticaNeueLTPro-BdCn
Hope it will work for you.
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.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I embed a custom font in an iPhone application?
I am stuck in the following problem:
I have to use the following font: Helvetica Neue LT Pro . Medium condensed and Bold condensed styles.
I first had them as otf files and I read somewhere that it might be better to have them as true-type fonts. So I converted them to .ttf files using http://www.freefontconverter.com/
What I did:
1) I added the fonts in my Resources bundle , checked to be sure they are listed in Copy Bundle Resources section.
2) I added them in the Fonts provided by application entry in Info.plist with the complete name and extension of my 2 files : helveticaneueltprobdcn.ttf and helveticaneueltpromdcn.ttf
3) I used this code to check the fonts were installed and get the name:
for (NSString *familyName in [UIFont familyNames])
{
NSLog(#"----------------");
NSLog(#"FAMILY: %#", familyName);
for(NSString *fontName in [UIFont fontNamesForFamilyName:familyName])
{
NSLog(#" %#", fontName);
}
}
4) The fonts were listed there , like this:
FAMILY: Helvetica Neue LT Pro
HelveticaNeueLTPro-MdCn
HelveticaNeueLTPro-BdCn
5) Still not working when trying to use [UIFont fontWithName:#"HelveticaNeueLTPro-BdCn" size:16]. It's not the font that I asked for , I guess it does not find it and uses the system default. If I change the size , there's no change - I can use size 16 or 46 , the result is the same.
6) I tried deleting and re-installing the app , clean project in XCode , everything I could think of.
Does anyone have any idea why this wouldn't work?
I googled a lot and I couldn't find a solution.
If it matters , I'm using XCode 4.3.2 , iOS SDK 5.1 and running on an iPad with iOS 5.1.1 installed.
Thank you.
Regards,
George
Finally got it...
Here's what I was doing:
MyCustomView *view = [[MyCustomView alloc] init];
//bla bla
In MyCustomView.m , in the init method I had this:
- (id) init
{
//create some labels and set their fonts.
}
The problem is that at the time at which I was setting the font , the parent view of the labels ( MyCustomView instance ) was not added to a superview.
I made a setFonts method that I called after I called init on the MyCustomView instance and when I set the fonts there, it worked!
Hope this helps.
Cheers!
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.
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.