Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting custom font to bold

I have successfully added a custom font to my project and it works just fine by doing this line of code amongst other things:

 [sideScoreLabel setFont:[UIFont fontWithName:@"Caveman" size:34]];

However I want this custom font to be bolded. I have researched this and everyone seems to be saying to add "-Bold" at the end of the font name or "-BoldMT" making it appear like the following:

 [sideScoreLabel setFont:[UIFont fontWithName:@"Caveman-Bold" size:34]];

When I run my project it does not seem to work. Does anyone know what I am doing wrong? Perhaps the font I am using does not work with Bolding?

Thank you!

like image 825
Alex G Avatar asked Dec 01 '22 23:12

Alex G


2 Answers

I have successfully added a custom font to my project and it works just fine by doing this line of code amongst other things:

Dude you added a CUSTOM FONT to your iOS bundle.

If you want a bold version of that font you need to provide one the system wont do it for you.

like image 60
deleted_user Avatar answered Dec 04 '22 04:12

deleted_user


You are on the right track when you mention the font not being able to be bolded. You can verify this with this bit of code that will encho out to console all available fonts, then you can look for your font in there.

NSArray *familyNames = [[NSArray alloc] initWithArray:[UIFont familyNames]];
  NSArray *fontNames;
  NSInteger indFamily, indFont;
  for (indFamily=0; indFamily<[familyNames count]; ++indFamily)
  {
      NSLog(@"Family name: %@", [familyNames objectAtIndex:indFamily]);
      fontNames = [[NSArray alloc] initWithArray:
          [UIFont fontNamesForFamilyName:
          [familyNames objectAtIndex:indFamily]]];
      for (indFont=0; indFont<[fontNames count]; ++indFont)
      {
          NSLog(@"    Font name: %@", [fontNames objectAtIndex:indFont]);
      }
      [fontNames release];
  }
  [familyNames release];
like image 41
box86rowh Avatar answered Dec 04 '22 06:12

box86rowh