Using custom fonts - iphone

So I'm able to use custom fonts by adding them to my Xcode project and info.plist like so:
http://iosdevelopertips.com/user-interface/load-and-access-custom-fonts.html
However, I tried adding another in the same way, but that UIFont doesn't seem to work for some reason. The UILabel just shows the default font setting. Is there a particular reason why one .ttf would work and another wouldn't?

As EmilioPelaez commented, font family names can sometimes be different from the file names. Using the NSLog technique NSLog(#"Fonts: %#", [UIFont familyNames]); can help to find out what the family name of added fonts is.

Related

Font not loading in XCode

Well, I want to import a new Font to my application but without success. I have the Fonts provided by application key in my .plist , I have my font in the Item 0 as a String and the value AdelleBasic_Bold.otf, I have added that Font to my project, and I am trying to use it with:
_myTextField.font = [UIFont fontWithName:#"Adelle Basic" size:15];
Adelle Basic is the header of the Font when I open it. I have also tried without any success:
_myTextField.font = [UIFont fontWithName:#"AdelleBasic_Bold" size:15];
Any suggestion?
This may well not true for all fonts, but in my experience, Xcode can be fussy, & I've never been able to get it to use otf fonts (anyone who has please post!), so I've always converted my fonts using this really excellent website - Online Font Converter
I convert them to ttf fonts, and they always seem to work fine - make sure you use the exact name (changing the filename of the font seems to stop it working too).
Hope this helps.
Below is the proper way to add fonts to your XCODE app (.otf fonts work fine):
Include your fonts in your XCode project
Make sure that they’re included in the target
Double check that your fonts are included as Resources in your bundle
Include your iOS custom fonts in your application plist
Find the name of the font
Credits and better explaination with images here
you can use only the third party fonts which have extension as ttf and the fonts which have otf extension will not work effectively and mostly doesn't work
Apart from assuring the 5 points, you could also try out the following snippet of code that prints out the installed fonts:
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family)
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
If the font that you want to use is not listed, then you missed in some of the 5 steps.
I just add font into project, check if font will copy inside bundle. Set up it on my Mac and directly use font inside Interface Builder. If you will have any problems solve they here.
I've seen some comments about tff and otf and I wouldn't agree, it could be that you are not using the correct font name, this doesn't mean the file name
to find the fonts you have installed in xcode run the
for family: String in UIFont.familyNames{
print(family)
for names: String in UIFont.fontNames(forFamilyName: family){
print("== \(names)")
}
}

Custom font is not working in my App?

In my iPhone app,
I have included two custom fonts and by referring this steps by stackoverflow questions....
How to include and use new fonts in iPhone SDK?
And Coded ....
[lbl setFont:[UIFont fontWithName:#"glyphish.ttf" size:[lbl minimumFontSize]]];
I am building this app for Base SDK 5.0
The answer is,
[lbl setFont:[UIFont fontWithName:#"glyphish" size:[lbl minimumFontSize]]];
Thanks to all.
First find that font in your available fonts list:
NSLog(#"fonts: %#", [UIFont familyNames]);
Then find and input the appropriate name.
You have passed a filename (glyphish.ttf) instead of the actual font name. Most likely, the font name is Glyphish, but you need to query it somehow: either using the Mac's "Font Book.app" or via code: first, you need to query the family names via [UIFont familyNames]. Then, use [UIFont fontNamesForFamilyName:] to get the actual font names to load. For example, if your font contains a bold variant its family name would be Glyphish but font name would likely be Glyphish-Bold.
You should correct name. It should not contain ttf in glyphish.ttf. For exact reference refer following image for that. Dakota is font name in my case.
The font name is not the name of the file. Thus glyphish.ttf is not a valid font name.
you have to use the font name, not the filename. you can check the name by opening the font file on yout mac.
Most probably the actual font name to be put in the app might be something else than glyphish.ttf .. i suggest opening font book and there checking the name of the font .and using that.
You need to check the font name it may be different then the font file name...try this link
Go to your application build phases and add your font files in copy bundle resources
Double click on the font file to open it in font book. Now see the name of the font on the top bar. Use this name in your code.

How to Display different Custom arabic fonts in iPhone application?

In my application i need to display arabic text with different custom fonts. I follow the scenario adding ttf files to info.plist.
As per above scenario i am successfully getting display text in different font style for ENGLISH text only. I am doing same thing for arabic font styles but here i am not getting. Why is going like that?
Please any one can help me
Thanks in Advance.
#Kareem , I took hint from Stackoverflow itself to load the fonts but could not get it working in first go. May be following steps can help you .
Add the font files to your project.
Make their entries in info.plist file
such as
you can now implement some method that loads your font somewhere in
application delegate
like
-(UIFont*) CustomFontWithSize:(float)size{
UIFont* customFont = [UIFont fontWithName:#"FX_Masa" size:size];
if(customFont == nil)
customFont = [UIFont systemFontOfSize:size];
return customFont;
}
If you notice then the name I have passes here is "FX_MASA" and not FX_MasaRegular , this was the point where I was wrong. The name that we need to use while fetching the font is the INSTALL NAME (Double click on the font to install the font on system and the name that appears in Font Book is the install name).
Hope this helps your problem as well. In case you come across any good method, please update here.
There is a nice UILabel extension in GitHub called "Font Label": https://github.com/zynga/FontLabel
This allows to load any TTF file and then draw ZLabel objects (ZLabel is an extension of UILabel) with this custom font. It is based on CoreGraphics and I tested with many custom fonts and proved to work correctly. I don't know of course the effect with arabic fonts, but it's worth a try and a feedback from you (to us and also the github project admins) is welcome.

Custom font in iOS app is used in places it shouldn't be

I've added the custom font "Helvetica-Condensed-Bold.otf" (font family Helvetica, font name Helvetica-Condensed-Bold) to my iOS app using the UIAppFonts Info.plist key. As expected, this font is used when I do the following:
someLabel.font = [UIFont fontWithName:#"Helvetica-Condensed-Bold" size:28.0];
But unlike what I expected, and unlike how this is supposed to work, this font is now also used in a bunch of places where I didn't want it to be, like in UIButtons and UILabels other than this one. In the iPhone Simulator, the font is even used in iOS's own status bar.
Would anyone of you know how to resolve this problem: to have to custom font only be used where I specifically say it should be?
Let's try some troubleshooting. Pick a different font and see if you have the same issue. Also, try renaming Helvetica-Condensed-Bold to something else (say HelveticaCondensedBold).
I had to use this font and I came upon this question. It looks like Helvetica Condensed Bold has been available since iOS 5.0 (http://iosfonts.com.)
I used
[UIFont fontWithName:#"HelveticaNeue-CondensedBold" size:12.0];

ttf font not available for iPhone in interface builder or simulator

I added a font file (.ttf) to my Xcode project, to resources. Also, I added it to the UIAppFonts in my info.plist.
When I want to use this font though, I don't even see it as a choice in IB.
After installing the font on my system, I started seeing it in IB, but still - changing to it doesn't change anything - some default system font is displayed in the Interface Builder as well as in iPhone emulator.
Are there any steps more I should do to be able to use my own font?
To use custom fonts with iOS you have to set them programmatically.
For example, suppose you have a font file called swellfont.ttf that you add to your project.
You then would go into your App-Info.plist file and add the full name of the file to the next index of the array keyed by UIAppFonts, as you mention.
<key>UIAppFonts</key>
<array>
<string>swellfont.ttf</string>
</array>
Then, to use the font:
label.font = [UIFont fontWithName:#"swellfont" size:12];
Assuming that label is a UILabel and that swellfont.ttf is not protected. It's important to note that UIFont's fontWithName is not referring to the filename, instead its wanting the actual name of the font. If you open the font with FontForge you can see this information by selecting Element > Font Info from the menu bar. There are probably cleverer ways to find this information out.
I use 2 fonts in an APP. The first one was automatically added to the "Copy Bundle Resources", the other was not. I had to add that one myself.
Call in code:
[labelName setFont:[UIFont fontWithName:#"OneGreatBigFont" size:40]];