Using a custom font with bold text in a UILabel

13,184

Solution 1

Try using @"Helvetica-Bold" as the fontName.

Solution 2

Try this,

NSArray *arr = [UIFont fontNamesForFamilyName:@"myFavoriteFont"];
NSString *fontName = [arr objectAtIndex:0]; //or [arr objectAtIndex:1], it depends
[label setFont:[UIFont fontWithName:fontName size:[fontSize intValue]]];

Solution 3

Try,

fontName = @"myFavouriteFont-Bold";
[label setFont:[UIFont fontWithName:fontName size:[fontSize intValue]]];

By using the the method fontWithName:size:, you can set the font name with style. Doc says that the fontName is the fully specified name of the font and this name incorporates both the font family name and the specific style information for the font.

Share:
13,184
Tushar Vengurlekar
Author by

Tushar Vengurlekar

14 years of experience in Software Development Expertise in Mobile Applications Native/Hybrid Web Application Developments Product/Project Management Team Building

Updated on June 08, 2022

Comments

  • Tushar Vengurlekar
    Tushar Vengurlekar almost 2 years

    I have an app where I am setting the font for a UILabel programmatically as below

    [label setFont:[UIFont fontWithName:fontName size:[fontSize intValue]]];
    

    wherein fontName is a string type variable that hold font name such as "Helvetica" and fontSize will hold the size of the font. This works fine for me. Now I want to make this text "Bold" how can I do that?

    boldSystemFontOfSize 
    

    works for system font. How can I achieve the same for user defined fonts ?

    Thanks.

  • Tushar Vengurlekar
    Tushar Vengurlekar almost 13 years
    This appears to be simple approach. Thanks.
  • Anna Billstrom
    Anna Billstrom over 9 years
    This worked for me- downloaded a font from Google Web fonts, and couldn't find the bold name. I printed out each in the loop and found the right name. for (NSString *fontname in arr){ NSLog(@"fontname: %@", fontname); } UIFont *font = [UIFont fontwithname:@"[insert name]"];