UITextField font style not changing - iphone

I have the following problem - I want to change the UITextField font to a custom one. I am using this line of code:
textField.font = [UIFont fontWithName:#"fontname.ttf" size:20];
I want to use this font:
Neurm.ttf
Can you please tell me what is wrong or just try it out and tell me is it working?

You doing wrong Because no need to set extension (fontname.ttf) in your string.
textField.font = [UIFont fontWithName:#"NEURM TTF" size:20];
and check following links how to use custom font in ios.
1.How to use custom font in iOS Apps?
2.iPhone Development: how to use custom fonts?

Its possible you may have not gone through some necessary steps to embed a custom font in your app.
Check;
iOS Custom Fonts
Can I embed a custom font in an iPhone application?
and see if you missed anything.

here
someTf.font = [UIFont fontWithName:#"AlexBrush-Regular" size:20];
This is working correctly no need to give .ttf ext

Related

How to set UILabel to use Arial Narrow (programmatically) just like we do on storyboard?

When we design a UILabel on Storyboards, we can set them as Attributed text, and it's possible to set the Arial Narrow font. But programmatically when we use the code above:
NSRange auxRange = NSMakeRange(0, [myString length]);
NSMutableAttributedString *attrStr = [myLabel.attributedText mutableCopy];
UIFont *newFont = [UIFont fontWithName:#"Arial Narrow" size:17];
[attrStr addAttributes:#{ NSFontAttributeName : newFont } range:auxRange];
myLabel.attributedText = attrStr;
We have a pointer to nil for newFont, this happen because the compiler could not find out Arial Narrow as font name.
My question is, why we can set Arial Narrow on Storyboard and we can not do the same on code?
If it's possible, what I doing wrong?
Print the font list of your phone:
for (NSString *familyName in [UIFont familyNames]) {
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"%#", fontName);
}
}
And then check the name of the font you want to add, it has to be there.
Use the name exactly as you see it printed.
If after trying #Antonio MG's answer you don't see the font you want, you will have to provide that font yourself.
First, locate the *.ttf font file and add it to your App's bundle
Second, add the name of the file to the list of Application provided fonts:
Then
EDIT: Just for the sake of completeness. Here is how you get the real font name:
Open Font Book
Locate the font you want
Hit the "Info" button
Use the name under "PostScript name"
Finally, you will be able to programmatically use that font in your application.
Hope this helps!
I'm surprised that the Storyboard editor lets you choose Arial Narrow. It doesn't for me.
In iOS6, Arial Narrow isn't available without using a custom font. You can find a list of the fonts available in iOS6 here. As touched on briefly in the WWDC session on using fonts with TextKit, iOS7 added support for downloadable fonts. This includes all OS X fonts where Arial Narrow is available.
So, as far as I know, to use Arial Narrow you have a couple of options depending on which version(s) of iOS you're targeting. You can bundle it with your app (this will work on iOS6 and iOS7) or you can write the code to use the built-in support to download and use the font (this will require iOS7).
Interface Builder displays a list of fonts that are installed on the OS X system, not the fonts available on iOS.
As a side note, why are you using Arial Narrow? Take a look at HelveticaNeue-Light on iOS.

How can we use custom font in an iOS app? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can I embed a custom font in an iPhone application?
How can I customize font in my iPhone app?
Is it possible?
How can I use this custom font in a UILabel?
I am trying to add MYRIADPRO-SEMIBOLD.OTF font in my App.
and the code is
UIFont *customFont = [UIFont fontWithName:#"MYRIADPRO-SEMIBOLD" size:35];
titleLbl.font = customFont;
And the Plist is
Try the steps below:
1. Make configuration in the info.plist as shown in Image
2. Now you should use that added file
UIFont *customFont = [UIFont fontWithName:#"fontName" size:size];
// further you may set That Font to any Label etc.
EDIT: Make Sure you have added that file in your resources Bundle.
Copy your font file into Resources.
In your application .plist create (if it exists 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
Then you can define this font in your application:
UIFont *CiutadellaBold = [UIFont fontWithName:#"Ciutadella-Bold" size:17.0f];
And use it in for instance in UILabel:
[uiLabel setFont:CiutadellaBold];
It is totally possible. Please check the following links to implement your solution.
iPhone Development: how to use custom fonts?
How to add custom fonts to an iPhone app?
how to use custom font in iphone application
Can I embed a custom font in an iPhone application?
I hope these links help.

How to load font family in iphone

I want to use separate font styles for iphone.
So, need to load font family.
How to load font family in iphone.
Can anyone please..
drag and drop your customFontName.ttf file to your project
Goto projectname-info.plist in supporting files. Add a key Fonts provided
by application -> add new item -> give value customFontName.ttf
use it where ever you want as,
myLabel.font = [UIFont fontWithName:#"customFontName" size:15.0];
Try this link.you shall get through

Why loading a font in an iPhone application only work for iOS >= 5.0

I'm trying to load a font into an application. I think I'm doing it well. But it doesn't work on iOS < 5.0.
I'm included the font files as resources (using otf files), add them to UIAppFonts array and testing the fonts on buttons. Like this:
In Info.plist:
<key>UIAppFonts</key>
<array>
<string>FrutigerNextPro-Medium.otf</string>
<string>FrutigerNextPro-MediumIta.otf</string>
<string>FrutigerNextPro-Light.otf</string>
<string>FrutigerNextPro-LightIta.otf</string>
</array>
Them in the buttons like this:
btt_01.titleLabel.font = [UIFont fontWithName:#"FrutigerNextPro-Medium" size:20];
btt_02.titleLabel.font = [UIFont fontWithName:#"FrutigerNextPro-MediumIta" size:20];
btt_03.titleLabel.font = [UIFont fontWithName:#"FrutigerNextPro-Light" size:20];
btt_04.titleLabel.font = [UIFont fontWithName:#"FrutigerNextPro-LightIta" size:20];
The problem is that FrutigerNextPro-Medium and FrutigerNextPro-MediumIta are only loaded in devices and simulator using iOS >= 5.0.
In devices and simulator with iOS < 5.0 it doesn't loads the font, I think it loads FrutigerNextPro-Light
and When I Log like this:
for (NSString *family in [UIFont familyNames]) {
NSLog(#"%#", [UIFont fontNamesForFamilyName:family]);
}
I get the font available in any platform:
(
"FrutigerNextPro-MediumIta",
"FrutigerNextPro-LightIta",
"FrutigerNextPro-Medium",
"FrutigerNextPro-Light"
)
I get the font available in any platform.
Can someone help me trying to understand what's going wrong.
Thanks
if you want to add custom font for older version of iOS then use this approch Can I embed a custom font in an iPhone application?
I discovered that it's a limitation, that only 2 variants of a single font face is supported.
Check this: http://www.iphonedevsdk.com/forum/iphone-sdk-development/59855-ipad-custom-font-issue.html
But still with no solution.. still unable to load FrutigerNextPro-Medium in iOS < 5.0..
I will try to convert the font..
EDIT:
I converted all fonts to ttf, but don't believe that was the solution.
What I did was (like in the forum says) change the Font Family Name.
Then I realize that is true, it's an issue, can't have 2 variants of a single font family.
Now its working.
Thanks anyway

Adding font in iPhone application

I'm trying to add a custom font to my iPhone app.
The font's name is: Susa-Regular.otf
I downloaded the font, installed it, dragged it over to xCode. Then I went into info.plist and added a row called "Fonts provided by application" and typed in Susa-Regular.otf
UILabel *myLabel = [[UILabel alloc]initWithFrame:frame];
[myLabel setFont:[UIFont fontWithName:#"Susa-Regular" size: 35]];
When I run the app, the font is still the same. I don't get any error messages either.
Any idea why it doesn't work?
More than likely the "font name" is not the same as the file name.
Open the font in Font Book and see how it represents the font name and use that instead with spaces removed.
You can also use [UIFont familyNames] and [UIFont fontNamesForFamilyName:] to discover what name iOS is using for it.
I figured it out. I dropped the dash and it worked perfectly!
[myLabel setFont:[UIFont fontWithName:#"SusaRegular" size: 35]];
I use the uifont-name-grabber posted at:
http://forgecode.net/2010/08/uifont-name-grabber/
Just drop the fonts you want into the xcode project, add the file name to its plist, and run it on the device you are building for, it will email you a complete font list using the names that UIFont fontWithName: expects.