This question already has answers here:
Can I embed a custom font in an iPhone application?
(32 answers)
Closed 8 years ago.
i am Newbie in iOS Development. I want to set a custom font to my Label. For that, I add my Font.ttf file in my project and add it to info.plist File "Fonts provided by application" My Font Name. Also I check in my Project Build Phases "Copy Bundle Resources" that contain my Font.ttf name but label font are not change please give me solution for it.
Code for it like as
[cell.headLabel setFont:[UIFont fontWithName:#"RobotoCondensed-Bold" size:10.0f]];
There are ton of examples online for doing this. A quick google search turns up this:
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
Take a look at this:
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
Try logging all the fonts to your console and see if yours is listed:
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
I am trying to use Helvetica CY font in my app. I have configured it as recommended by apple docs.
The custom font shows up in dropdown in Storyboard, but unable to use the same font programatically in my class file.
I have logged all font families available for the app, but "Helvetica CY" is not printed on console log.
Any help will be appreciated.
Thanks!
Its simple only. Its working for me in xcode6.1 too.
Try using this steps :
Step 1: Include your fonts in your XCode project
Step 2: Make sure that they’re included in the target
Step 3: Double check that your fonts are included as Resources in your bundle
Step 4: Include your iOS custom fonts in your application plist
Step 5: Find the name of the font
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
Step 6: Use UIFont and specify the name of the font
label.font = [UIFont fontWithName:#"Helvetica CY" size:20];
Apple provides a set of fonts to customize our application and also allow us to add custom fonts.
Steps
Copy the font files(.ttf or .otf) to main bundle.
Add the file names into info.plist as a new array named "Fonts provided by application".
It is very important to add the post script name of fonts into this array. That means each font have the font name(with extension) and its postscript name in info.plist.
To find the Post script name,just open the Fontbook application in mac and then add the font file. After adding the font file into font book just look at the information tab of that font,there we can find the Post script name.
Using is pretty simple, use the post script name of the font,
nameLabel.font = [UIFont fontWithName:#"HelveticaCY-Plain" size:22];
I made the same mistake. The key is the answer above:
for (NSString* family in [UIFont familyNames]) {
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family]) {
NSLog(#" %#", name);
}
}
I included in my project folder the GOTHIC.TTF file.
And in my Info.plist I included GOTHIC.TTF in "Fonts provided by application".
But surprise! The font it is not called "GOTHIC", but "CenturyGothic".
[cell.textLabel setFont:[UIFont fontWithName:#"CenturyGothic" size:24]];
just go throw this link and follow steps.
it is having all steps
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
In case someone is interested in Swift 3 code for getting fonts:
for family in UIFont.familyNames
{
print("Family: \(family)")
for name in UIFont.fontNames(forFamilyName: family)
{
print("Name: \(name)")
}
}
I know this question has been asked before, but so far have not found an answer to my problem. I am trying to use a custom font (Rockwell) in my app, but can't get it to load in.
I have used the correct name from Font Book, which is just "Rockwell". I've added the file to the project, and its target is the project. I've added the file to the plist, and also to the bundle resources.
I'm using the following code to set the font of a label, with no luck.
UIFont *customFont = [UIFont fontWithName:#"Rockwell" size:18.0];
[self._textView setFont:customFont];
It also doesn't appear when I run something like:
NSLog(#"Available fonts: %#", [UIFont familyNames]);
What am I missing?
Downloaded .ttf file from a different source, and now it works.
i have added a custom font - one which i have downloaded from from the net. it is in TTF format and can be used on other programs on my mac. (Successfully added it to font book and used in fireworks).
I have added the key to the info .plist but the font doesn't seem to work.
When i NSLog the font it is null so i am assuming it isn't finding it.
The TTF is called LONDON__.TTF but has a name as London font.
What should i use as the font and add to the info.plist for this to work?
Thanks
Dan
Application fonts resource path = LONDON__.TTF
NSLog(#"%#",[UIFont fontWithName:#"London font" size:22]);
and
NSLog(#"%#",[UIFont fontWithName:#"LONDON__.TTF" size:22]);
Both of them return Null.
Although the file is named LONDON__.TTF the font appear as everyone in Font Book. is this the issue?
Look at all the available fonts
Objective-C:
for(NSString* family in [UIFont familyNames]) {
NSLog(#"%#", family);
for(NSString* name in [UIFont fontNamesForFamilyName: family]) {
NSLog(#" %#", name);
}
}
Swift:
for family: String in UIFont.familyNames() {
print("%#", family)
for name: String in UIFont.fontNamesForFamilyName(family) {
print(" %#", name)
}
}
..if it's not there, install again
Copy the .ttf file into your project (i.e. drag it to the resource folder in the Project navigator).
In your Info.plist add an entry with the key Fonts provided by application with an Array type. As Item 0, add a String value corresponding to the font file name (e.g. OpenSans-ExtraBoldItalic.ttf).
Make sure the font file is included in the copy bundle resources list under the project settings.
You need to make sure the font file is included in the copy bundle resources list under the project settings. My font wouldn't show up in [UIFont familyNames] till I added it here as it was not automatically included when added to the project.
Both of those names sound wrong. Assuming you've correctly added it to your plist, use something like
NSLog(#"Fonts: %#", [UIFont familyNames]);
to see what its internal name is.
BTW, be sure that the licensing of the font allows embedding. Many commercial fonts do not.
I want to use HelveticaNeue-UltraLight in my ios application. I'm adding the font file as a resource to my project and adding the "Fonts provided by application" key in the plist file. The file name is HelveticaNeue.dfont and I've added it to the key array.
When I check for the available fonts I can see it now...
NSArray *fonts = [UIFont fontNamesForFamilyName:#"Helvetica Neue"];
for(NSString *string in fonts){
NSLog(#"%#", string);
}
1-07-08 17:32:57.866 myApp[5159:207] HelveticaNeue-Bold
2011-07-08 17:32:57.866 myApp[5159:207] HelveticaNeue-CondensedBlack
2011-07-08 17:32:57.867 myApp[5159:207] HelveticaNeue-Medium
2011-07-08 17:32:57.867 myApp[5159:207] HelveticaNeue
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-Light
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-CondensedBold
2011-07-08 17:32:57.868 myApp[5159:207] HelveticaNeue-LightItalic
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-UltraLightItalic
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-UltraLight // HERE IT IS!
2011-07-08 17:32:57.869 myApp[5159:207] HelveticaNeue-BoldItalic
2011-07-08 17:32:57.870 myApp[5159:207] HelveticaNeue-Italic
But when I try to get it with [UIFont fontWithName:#"HelveticaNeue-UltraLight" size:12] I just get HelveticaNeue-Light..
I'm getting no errors or warnings.
Help please!
Not only does the file needs to be added to the project, but it needs to be added to the target as well.
Sometimes (as in my case), when drag and dropping the ".ttf" file in Xcode, the "add to target" is not checked. This means the file is actually visible in your project, but it is not embedded in the app.
To make sure it is:
Click on the project's name (left pane)
Then on the target (middle pane)
Then "Build Phases" (third tab on the right pane)
Then "Copy Bundle Resources"
You should see the font file in that list.
I think you're having the same problem I had : there's a bug in iOS where it is not able to use more than 2 fonts from the same family.
See blog post here for details and solution : http://www.pixeldock.com/blog/uifont-problem-when-using-more-than-2-custom-fonts-of-the-same-font-family/
after adding Font file in Bundle
"Font Provided by Application" property click on drop down arrow
and enter your font name with extension
It is working with different variations of the same font(even in IOS 8). I'll post my mistake just in case someone has the same problem...
I was using font's filename instead of the font name.
A useful solution is print all the fonts available and look for the one I was using.
In Swift would be:
for fontFamilyNames in UIFont.familyNames {
for fontName in UIFont.fontNames(forFamilyName: fontFamilyNames) {
print("FONTNAME:\(fontName)")
}
}
I found this useful tutorial in: Code with Chris
Open Font Book application. If you installed the fonts yourself, go to user, look for the fonts you want and use the PostScript name of the font in your xcode project.
It should work even for different font variations of the same family.
Drag your font files (.ttf or .otf) into project's bundle.
Then select all those fonts > on your xcode's right panel make sure the Target membership is enabled.
Select project from the navigator panel > select Build phases > under Copy Bundle Resources verify all your fonts are listed. If not, add one by one using + icon.
Info.plist > select Fonts provided by application > add your fonts one by one (e.g., Helvetica-Bold.ttf).
While this probably won't help the OP, it might be useful to others.
With iOS 5, Helvetica Neue is automatically included; you don't have to add this custom font to the bundle. It's even possible to use that font family directly from Interface Builder, which is extremely handy.
Try this this will be also heleful for you.
[compete_Label setFont:[UIFont fontWithName:#"Helvetica-Bold" size:12]];
After spending hours, I came to know that the Name for the font we need to add is not the file name of the font but the actual Font name. I was trying to include font file bonveno.ttf. I have included the filename along with extension in info.plist and was able to see the font in the Copy Bundle Resources list. My code was like
self.label.font = [UIFont fontWithName:#"bonveno" size:30];
that was causing the problem. Then I double clicked the font file from Finder to see the preview of the font. That time I noticed the name of the font in the preview window as BonvenoCF. So I added that name in the code like
self.label.font = [UIFont fontWithName:#"BonvenoCF" size:30];
Worked like charm!! Can't live without this cute font in my apps.
Try with spaces:
[UIFont fontWithName:#"Helvetica Neue UltraLight" size:12];
See Certain fonts not showing up?
I ended up buying the font Helvetica Neue UltraLight from a third party, added it with no problems.
In order to use custom fonts in iOS, just add your fonts by drag & drop to your project. Mention the array of font names with extension in Info.plist with key "Fonts provided by application". Then print all font family names using below code :
for (NSString* family in [UIFont familyNames])
{
DebugLog(#"FONT FAMILY: %#", family);
for (NSString *name in [UIFont fontNamesForFamilyName: family])
{
DebugLog(#" %#", name);
}
}
Console print :
Arial Hebrew
ArialHebrew-Bold
ArialHebrew-Light
ArialHebrew
Calibri
Calibri-Bold
Calibri
Georgia
Georgia-BoldItalic
Georgia-Bold
Georgia-Italic
Georgia
Then from console, you will get the actual font-names (As above). Use below code to create font -
In core text :
CTFontRef fontRef = CTFontCreateWithName((CFStringRef)fontName, fontSize, NULL);
In UIKit :
UIFont *font = [UIFont fontWithName:fontName size:10];
Note : here fontName = #"Calibri-Bold" is without extension.
In addition to:
adding the font file names to the info.plist under "Fonts provided by
application"
adding the actual files to the project.
You also have to make sure that under Targets -> Build Phases -> Copy Bundle Resources has the actual filenames of the custom fonts.
To check if they have appeared, you can do something like:
UIFont.familyNames.forEach { (name) in
print(name)
}
Another thing to check is on a Mac: Open the app Font Book. Then go file -> file validation and open the font. If something is failing (even with a warning) in there iOS generally rejects loading the font in the app with no errors.
If this is the case then you can fix the errors by opening the font in a free app called "Typelight" And resaving the font "Save as".
In addition to the well explained #Ben answer, if you're still not getting your fonts, Just use or assign your font to any Label in one of your Storyboard, You will start getting it using this code
If you still unable to get font using [UIFont fontWithName:#"Font-Regular" size:11]; There must be problem in naming. Stop at any Breakpoint in debugger and Debug it using different names, and see which po prints object that is not nil
po [UIFont fontWithName:#"FontRegular" size:11];
or
po [UIFont fontWithName:#"Font Regular" size:11];
or
po [UIFont fontWithName:#"Font-Regular" size:11];
You will get <UICTFont: 0x7fe2044021d0> font-family: "Interstate-Regular"; font-weight: normal; font-style: normal; font-size: 11.00pt for actual font name otherwise you will get nil
note that add .ttf end of each Fonts provided by application name
It's an old question but I'd like to emphasize that we must write font file name WITH EXTENSION into info.plist.
It was particularly my mistake: I missed extensions. But the very interesting thing that iOS successfully loaded three fonts even when the extensions were missed.
Once I've added extensions all 12 fonts were loaded.
Good article:
https://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/