简体   繁体   中英

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!

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.

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];
  1. Find in Spotlight "Font Book"
  2. Open it and find your font in the list of fonts
  3. As you can see, any font has several names. In your code you always should use PostScript name of your font. Sometimes PostScript name is not similar with file name of your font.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM