0

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?

Community
  • 1
  • 1
Sagar Joshi
  • 934
  • 13
  • 20
  • yourButton.titleLabel.font = [UIFont fontWithName:@"Ubundu" size:20.0]; – Arun Sep 03 '15 at 12:47
  • @Spynet Apparently there isn't any problem with code. Like If I use [self.titleLabel setFont:[UIFont fontWithName:@"Verdana" size:20.0]]; Then It works just fine. – Sagar Joshi Sep 03 '15 at 12:53
  • 1
    possible duplicate of [How to include and use new fonts in iPhone SDK?](http://stackoverflow.com/questions/4969329/how-to-include-and-use-new-fonts-in-iphone-sdk) – iAhmed Sep 03 '15 at 12:55
  • So your custom font adding process is wrong , the above link sounds good – Arun Sep 03 '15 at 12:55
  • 1
    Already answered many times over stackoverflow. http://stackoverflow.com/questions/4969329/how-to-include-and-use-new-fonts-in-iphone-sdk http://stackoverflow.com/questions/14376941/how-to-use-custom-fonts-in-iphone-sdk/14377069#14377069 – iAhmed Sep 03 '15 at 12:57
  • @iAhmed I've already done those steps. That's what I'm telling it that font is included in info.plist file. then also it is not working. – Sagar Joshi Sep 03 '15 at 13:00

1 Answers1

-1

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

iAhmed
  • 6,556
  • 2
  • 25
  • 31
  • No it's not. Only when I add label from interface builder and set its font to ubuntu then it's name is printed. – Sagar Joshi Sep 03 '15 at 13:11
  • It means your fonts are not being added in your project resources. OR not added correctly in plist. – iAhmed Sep 04 '15 at 06:06