can't set custom font to uibutton programmatically - ios

I'm trying to use ubuntu font for uibutton programmatically (button is also created programmatically and it's custom). Here's what I've done.
[self.titleLabel setFont:[UIFont fontWithName:#"Ubuntu" size:20.0]];
but no luck. I've checked everything.
- font is included in build phases
- I've added font in info.plist
But when I add label from interface builder and set ubuntu font from attribute inspector then everything works fine. Font is applied also on uibutton. but when I remove that label problem persists.
What's going on here?
Edit:
I've already followed steps provided in answers of similar problems. like this.
How to include and use new fonts in iPhone SDK?

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);
}
}
In Alphabetic Order:
for (NSString* family in [[UIFont familyNames] sortedArrayUsingSelector:#selector(compare:)])
{
NSLog(#"%#", family);
for (NSString* name in [[UIFont fontNamesForFamilyName:family] sortedArrayUsingSelector:#selector(compare:)])
{
NSLog(#" %#", name);
}
}
Get of your font from printed values and then use it as you are already doing.
Hope it helps

Related

Add custom font family in React Native iOS

I would like add custom font family on my React Native App on iOS. I've no problem with Android, but i've an error in iOS :
Unrecognized font family 'dinproRegular'
I've use this link for setup my font, but no result.
File name : dinproRegular.ttf
Call in react-native : fontFamily: "dinproRegular" // Test with "Dinpro Regular" too
No result :(
Anyone have idea ?
Just check the fonts that are currenly installed in Ios or Android:
https://github.com/react-native-training/react-native-fonts
If you want to add custom fonts:
https://medium.com/#danielskripnik/how-to-add-and-remove-custom-fonts-in-react-native-b2830084b0e4
Hope it helps!
In iOS, you can see what font name you should use in code to let it work
Use below code in AppDelegate.m to get all font names supported in your app.
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}

How do I set bold font on UILabel in iOS?

I want to set bold font on UILabel. I generate label by coding. when i try to set bold font on label ios set system regular font but i want to set 'Noto sans-Bold' font. In storyboard set font completely.
My code is
UILabel *lblName=[[UILabel alloc]initWithFrame:CGRectMake(0, 25, 100, 21)];
lblName.text=#"Hello World";
[lblName setFont:[UIFont fontWithName:#"Noto Sans-Bold" size:15.0]];
[self.view addSubview:lblName];
If you haven't got the formatting of your font title correct, it will automatically default back to system font.
The issue is with your font name and since Noto isn't native it's going to be difficult to know exactly what name you need to provide.
Make sure you have added that font to your project.
You can check your available fonts by running this code:
SWIFT
for familyName in UIFont.familyNames() {
print("\n-- \(familyName) \n")
for fontName in UIFont.fontNamesForFamilyName(familyName) {
print(fontName)
}
}
OBJECTIVE-C
for (NSString *familyName in [UIFont familyNames]){
NSLog(#"Family name: %#", familyName);
for (NSString *fontName in [UIFont fontNamesForFamilyName:familyName]) {
NSLog(#"--Font name: %#", fontName);
}
}
lblname.font = [UIFont fontWithName:#"Noto Sans-Bold" size:18];
and one more thing check your font correctly it is available in list or not.
Here is a list of available fonts .
List of available fonts
EDIT:-
or if you want to set font which not available in xcode then you have to first install it in XCode
please follow this tutorial.
Install custom fonts
As said by Jilouc follow this procedure.
Add the font files to your resource files
Edit your Info.plist: Add a new entry with the key Fonts provided by application.
For each of your files, add the file name to this array
On the example below, I've added the font "DejaVu Sans Mono":
In your application you can
the use [UIFont fontWithName:#"DejaVuSansMono-Bold" size:14.f].
Or if you want to use it in html/css, just use font-family:DejaVu
Sans Mono;

iOS 8 custom UIFont does not appear in fontFamily listing even though it shows in IB

in iOS 8, Xcode6, I add a custom font, in info.plist. It's there in Build Phases. It's there in the storyboard, but it does not list in familyNames. I've read every other Stack Overflow post on this several times.
The file is CODBARD.TTF. The actual postscript name is codabard.
for (NSString* family in [UIFont familyNames])
{
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family])
{
NSLog(#" %#", name);
}
}
It's not there.
And this line of code just produces a nil result
UIFont *customFont = [UIFont fontWithName:#"codabard" size:20];
You have to use that font somewhere in a xib or storyboard
I create a blank xib and add labels which use the desired font, than i don't use the xib nowhere, but this loads the custom fonts

Custom font not Showing

I want to add custom font in my application . I am adding in my project.
and then adding in .plist file.
and my code is
UIFont *CiutadellaBold = [UIFont fontWithName:#"Light up the World with accented characters" size:90.0f];
// Do any additional setup after loading the view, typically from a nib.
[label setFont:CiutadellaBold];
label.text =#"hello";
But the text does not show up in my custom font. What am I doing wrong?
The name of your font is most likely not identical to file name. You can find out names of fonts available in app like this:
for (NSString* family in [UIFont familyNames]) {
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName:family])
NSLog(#" %#", name);
}
Your font name is not equals to the file name, you should get in in file info
First check your font is installed in "Font Book" application in your mac. copy the "postScript name" and use in your code.
UIFont *CiutadellaBold = [UIFont fontWithName:#"postScript name" size:90.0f];
Please refer attached screen shot.
Note:This is for iPhoneSimulator. You also check this in device. Sometime this issue not occur in device.

Wont change font to customFont

I've looked through almost every thread on creating a custom font for a Label. What am i doing wrong?
plist:
bundle resources:
resources:
The code:
UILabel *headLine = [[UILabel alloc] initWithFrame:CGRectMake(screenWidth/2-55, screenHeight/2-100, 110, 35)];
headLine.textColor = headlineColor;
headLine.text = #"HEADLINE";
UIFont *pacificoFont = [UIFont fontWithName:#"Pacifico" size:35.0f];
headLine.textAlignment = UITextAlignmentCenter;
[headLine setFont:pacificoFont];
[self.view addSubview: headLine];
There are a lot of errors that can be done with custom fonts (more info here).
However, I suspect that your family name is wrong. Use this to print the available family names and check if "Pacifico" is there:
for (NSString* family in [UIFont familyNames]) {
NSLog(#"%#", family);
for (NSString* name in [UIFont fontNamesForFamilyName: family]) {
NSLog(#" %#", name);
}
}
When you declare a UIFont with a custom name you have to specify the family of the font, and not the filename of the ttf file :)
follow the below steps:
1)Add your custom font files into your project using Xcode as a resource
2)Add a key to your Info.plist file called UIAppFonts.
3)Make this key an array
4)For each font you have, enter the full name of your font file (including the extension) as items to the UIAppFonts array
5)Save Info.plist
6)Now in your application you can simply call [UIFont fontWithName:#"CustomFontName" size:12] to get the custom font to use with your UILabels and UITextViews, etc…
note: Make sure the fonts are in your Copy Bundle Resources.

Resources