Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a custom font with bold text in a UILabel

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.

like image 419
Tushar Vengurlekar Avatar asked May 24 '11 11:05

Tushar Vengurlekar


2 Answers

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

like image 72
Abizern Avatar answered Oct 08 '22 01:10

Abizern


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]]];
like image 32
Cao Huu Loc Avatar answered Oct 08 '22 01:10

Cao Huu Loc