Non-System fonts not working on iOS6 - ios

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.

Related

Embedding font in ios?

I have embedded font in ios, like the normal version italics and all by following methodes.
1.Added font to project folder.
2.Added font names "MuseoSans_100.otf" inside "Fonts provided by application" in info.plist.
3. created UIFont in viewdidload method
UIFont *newfont = [UIFont fontWithName:#"MuseoSans_100" size:13.0];
[labelname setFont:newfont];
but when i run this in simulator, i can see the font and size are not changing.
Please help.
You can use the fontNamesForFamilyName: method to retrieve the specific font names for a given font family.
Check the font family
NSLog(#"%#",[UIFont fontNamesForFamilyName:#"MuseoSans_100"]);

Issue with adding custom fonts

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];

Set own custom colors and fonts in UIColor

I am new to ios, Just need to clear two doubts:
1.I am aware that to set custom colors we use following method:
[UIColor colorWithRed: 127 green:127 blue:127 alpha:1]
How do I find out from an Image what parameters for RGB are?(Its not an xcode question but I need to know).
2.How to add my own custom fonts in my project. I have added the file name in "fonts provided by application". But I am still not able to get the result in desired font.
The file name is ExpertSans-ExtraBold.ttf .following is the code used:
setFont:[UIFont fontWithName:#"ExpertSans-ExtraBold" size:48.0f];
for set color
[UIColor colorWithRed: 127.0/255.0f green:127.0/255.0f blue:127.0/255.0f alpha:1.0];
for set custom font
How to use custom font in iOS Apps?
iPhone Development: how to use custom fonts?
For number 1, if it's not an Xcode question, you have an app located in /Applications/Utilities on your mac, which lets you get the color of anything showing on your screen. (sorry, I don't know the name of the app in english, but it may have "color" in it). Then set the UIColor as you did : [UIColor colorWithRed: 100.0/255.0f green:200.0/255.0f blue:150.0/255.0f alpha:1.0];
For number 2, the name of the font is not always the name of the file. Once you added your font to the project, use this to log a list of all the font names available in your app :
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
Put this code in the AppDelegate in application:didFinishLaunchingWithOptions:
Once you found your font name, use myLabel.font = [UIFont fontWithName:#"My-Font-Name" size:10]; to set the font.
Try to use this one
[UIColor colorWithRed: 127/255.0f green:127/255.0f blue:127/255.0f alpha:1];
You are right but i think you are not getting proper font name. So do this to get proper name of font. See in this pic and set this name to your font.
set your font like this
setFont:[UIFont fontWithName:#"BankGothic Md BT" size:48.0f];
you can not get the whole image color but you can get the color of pixel
iPhone Objective C: How to get a pixel's color of the touched point on an UIImageView?
How to get pixel data from a UIImage (Cocoa Touch) or CGImage (Core Graphics)?
For font you have to give font name not file name
lblName.font=[UIFont fontWithName:#"Myriad Pro" size:15]; // where my file name is MyriadPro.ttf
Please check label.font = [UIFont fontWithName:#"Font-Name" size:10];
and put NSLog(#"%#",label.font);
If you find null then i think there is problem in the name you are giving.
Please also ensure when you are adding the font's file .ttf in your project it is also included in your target application. When you copy .ttf from other location to resource folder then it asks to copy to destination, and on that place you have to add it to the target application also by using check mark. If you suspect you haven't included to your target application. Please remove the files and add the again.
Hope this helps.

UIFont custom font not displaying on device

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.

Changing the font for labels in my project

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.

Resources