I have a problem with custom font. Namely it's Tw Cen MT.ttf
It's the same problem as in here:
Custom font not showing on device, but does on simulator
Except the given solution doesn't work for me.
I have done exactly what you should do:
Added Font to Info.plist
Added Font to Copy Bundle Resources section in Build Phases.
Used font programmatically by name not filename.
It still doesn't work. What's more interesting - when I list available fonts:
NSLog(#"%#", [UIFont familyNames]);
It shows me my font on simulator but does not show it on the device. I tested it both on the new iPad and iPhone 4 with iOS 6.
Any advice?
Be sure not to confuse the family name with the font name. This is the code I use to check the real name of my fonts.-
NSArray *familyNames = [UIFont familyNames];
for (NSString *aFamilyName in familyNames) {
NSArray *fontNames = [UIFont fontNamesForFamilyName:aFamilyName];
for (NSString *aFontName in fontNames) {
NSLog(#"%#", aFontName);
}
}
Make sure you got the name of the font right. The simulator is not case sensitive whereas the phone is.
Related
For my iOS project i need to use custom fonts. I added fonts in Resources/Fonts folder. And register the fonts in Info.plist like this. In storyboard i am getting custom fonts like this but the fonts not affecting in design. The font style drop down always empty see here "www.tiikoni.com/tis/view/?id=1f07d04". I m working in .storyboard file not .xib
What have i done wrong?
Xamarin studio version - 5.10.3
Fonts used - Exo-SemiBold.ttf, Montserrat-Bold.ttf
Ran into a similar problem. My custom fonts didnĀ“t show up in Xcode at all.
Solution was to move fonts from /Resources/Fonts/ up to /Resources/ (And updating Info.plist accordingly). Doing so made them show up in Xcode.
Try setting font programmatically.
After adding reference of your Font file in plist using "Fonts provided by application" key.
Then Log available fonts in AppDelegate method like this
NSArray *fontFamilies = [UIFont familyNames];
for (int i = 0; i < [fontFamilies count]; i++)
{
NSString *fontFamily = [fontFamilies objectAtIndex:i];
NSArray *fontNames = [UIFont fontNamesForFamilyName:[fontFamilies objectAtIndex:i]];
NSLog (#"%#: %#", fontFamily, fontNames);
}
In these logs you can find exact name of the font you want to apply.
I'm trying to use fonts from the Open Sans family. I added the fonts to my Xcode project, I checked that they were added to my application's resources bundle and I added the fonts to my Info.plist file.
When I edit a XIB in Interface Builder, I can use Open Sans font on UILabels when selecting Custom in the font dropdown menu. The font are correctly rendered on the preview in Interface Builder, but then when I launch the application on the device, the font is not applied to the labels.
I tried setting the font programmatically, but that didn't work either. And I'm not getting any warning nor error.
What did I forgot to be able to use a custom font?
The behavior has been the same on an iPad Air running iOS7 and on an iPhone 6 running iOS8.
Go to Target -> Build Phases -> Copy Bundle Resources , in there you check if the font file is there, if not press the plus button and add it manually. Sometimes the font files are not added automatically to the bundle resources.
Hope this helps.
Just make sure all the fonts really are available in the bundle, try printing all fonts and check if you are using the correct name.
You can very easily do this with following code in app delegate's didFinishLaunchingWithOptions method:
for (NSString *familyName in [UIFont familyNames]) {
NSLog(#"Family Name : %#", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"\tFont Name : %#", fontName);
}
}
or in Swift:
if let familyNames = UIFont.familyNames() as? [String] {
for familyName in familyNames {
println("Family : " + familyName)
if let fontNames = UIFont.fontNamesForFamilyName(familyName) as? [String] {
for fontName in fontNames {
println("\tFont : " + fontName)
}
}
}
}
The swift code is not the most efficient, but should work for checking if the fonts exist in the bundle.
What worked for me was when I added the font to check the "Add to targets" thick in front of my app name.
See image example here :
Ensure you have added the fonts in your Info.plist. There is an entry called "Fonts provided by application" which must contain all font files you want to use.
I just had the same problem... still kind of having... I wanted to mix fonts in the same label, which did not work...
The workaround was that I tried to change in the IB attributes inspector of the label try to change Text dropdown from Attributed to Plain... The font did change in the device... so I think this is a bug in Xcode.
Are you adding the font to your info.plist exactly how the font is spelt with the inclusion of its file extension? For example, OpenSans.ttf is different than opensans.ttf or just opensans. To be 100% sure of the file name right click on your font file, click on Get Info, and then check the Full Name description.
To add the font programmatically leave the file extension off. For example,
myLabel.font = [UIFont fontWithName:#"OpenSans" size:32];
If you are using webfont then download.ttf file and drop it into your project . Check mark on copy items if needed
Next add this on info plist
<key>UIAppFonts</key>
<array>
<string>Your fontname.ttf</string>
<string>Bakersfield Bold.ttf</string>
</array>
Now take a look the font family name. Which you will find on font file also. From where you have downloaded you will get there also. Like i added font which ttf file name is : Bakersfield Bold.ttf for this fontname is : Bakersfield-Bold
Thats it Happy coding.
Okay, so I'm trying to a custom font into an iOS 7 application
I've added the .ttf file into the "Supporting Files" Folder, I've added a new key which has the .ttf file specified, the .ttf file is in the "Copy Bundle Resources" area under "Build Phases" and in my *.m file I have this code... [UIFont fontWithName:#"Minecrafter_3" size:12]; By the way the "Minecrafter_3" bit is the name before the .ttf of my font.
Then I go into my main.storyboard, highlight the text in my label that I want to be that certain font, I go into the "Fonts" drop down menu and the font is not there, all that is there is the default fonts, with the "Custom" font. I tried using the "Custom" font but all it is, is "Helvetica Neue", which is not my font. I know that this is really long but I've been stuck on this for around 1 week now. Please help me!!!
first You can check your font added to your project or not by using the below code.
- (void)viewDidLoad{
[super viewDidLoad];
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" Sub names: %#", name);
}
}
}
for example CourierNew is our font. I declared like this
[UIFont fontWithName:#"CourierNew" size:40.0f];
but actually this is not a font name.
Courier New // this one cannot use like font name
//below are font names
CourierNewPSMT
CourierNewPS-BoldMT
CourierNewPS-ItalicMT
CourierNewPS-BoldItalicMT
we have to give sub names like this
[UIFont fontWithName:#"CourierNewPSMT" size:40.0f];
Now it should work.
Sounds like you forgot to add the font file to the plist under "Fonts provided by application"
Check out this step by step tutorial:
http://codewithchris.com/common-mistakes-with-adding-custom-fonts-to-your-ios-app/
The previous comments where correct about opening the font file to find the name of the font family, not the file name to use here:
[UIFont fontWithName:#"Minecrafter_3" size:12];
I've never had this problem before. But I can't get any font to show up besides the system font. I wanted to use helvetica, but that wasn't working, I have tried setting my UILabel's to Farah just to see if it would work and it doesn't. However, if I run in the simulator (with iOS7) then it seems to work fine. I've tried setting fonts on the storyboard. Then tried setting it programatically,
self.titleLabel.font = [UIFont fontWithName:#"Farah" size:25];
Has anything changed with the new Xcode that won't allow non-system fonts?
Add all non-system fonts to your application and include to .plist file in 'Fonts provided by application' section.
After you can use fonts in your application : [UIFont fontWithName: #"TitilliumText25L-400wt" size:14];(replacing "TitilliumText25L-400wt" to corresponding font name).
P.S. If you have a problems with detection of real font name use FontBook application or
the code snippet bellow which show you all available fonts for your application.
for(NSString* family in [UIFont familyNames]) {
NSLog(#"%#", family);
for(NSString* name in [UIFont fontNamesForFamilyName: family]) {
NSLog(#" %#", name);
}
}
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.
For more, check this out.
Getting font names right is not easy. Run this code to learn the available names:
for (NSString* s in [UIFont familyNames])
NSLog(#"%#: %#", s, [UIFont fontNamesForFamilyName:s]);
Of course, if setting a feature of self.titleLabel does not work, you should also make sure that self.titleLabel is not nil.
My client wants me to change the label font to "Interstate-bold". I have installed the font. I dragged the font to the resource folder in Xcode and added it to the Info.plist but it is not supported yet. What else do I need to do?
I think you followed correct steps to apply this fonts in app.
You can check exact name of font supported, by following way:
NSArray *fonts = [UIFont fontNamesForFamilyName:#"interstate"];
NSLog this fonts array and give that exact name in the fontName parameter llike this
[UIFont fontWithName:#"Interstate-Bold" size:14.0];
I am getting this, plz check at ur end.
So as you say you have:
added asset
in plist: Fonts provided by application, then name of the font FSAlbert.otf [*.otf]
placing the used name to your label:
the name of the font is not the same as the name you put on your label is different,
self.myLabel.font = [UIFont fontWithName:#"FS Albert" size:14];
look what is the name of that font for example in photo shop [or font book], and that would be the name for your label.font
Check in font book the name of the font.
Most probably the font name in the file name doesn't matches what is required to be given in iOS app.
So check what is the font name in font book and put it the app.