简体   繁体   中英

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.

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

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]]];

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.

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