How to create bold UIFont

我是研究僧i 提交于 2019-12-03 10:35:04

问题


I am doing some word wrapping in my tableview as some of the values are so big they go off the edge of the screen.

However, the font and size and boldness dose not match the default settings of the table view and was hoping someone could help me fix that up.

This is what I am doing to set the fields:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellText = @"Go get some text for your cell.";
    UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
    CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
    CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];

    return labelSize.height + 20;
}

回答1:


If you're using the version of Helvetica that is bundled in iOS, you can simply do:

[UIFont boldSystemFontOfSize:17.0];



回答2:


You can look into the fontNamesForFamilyName: method.

Specifically for Helvetica there are these families

NSLog(@"%@", [UIFont fontNamesForFamilyName:@"Helvetica"]);
"Helvetica-LightOblique",
Helvetica,
"Helvetica-Oblique",
"Helvetica-BoldOblique",
"Helvetica-Bold",
"Helvetica-Light"



回答3:


You have to ask for the font specifically, for example

[UIFont fontWithName:@"Helvetica-Bold" size:17.0]

Here is a list of available fonts: http://www.iphonedevsdk.com/forum/iphone-sdk-development/6000-list-uifonts-available.html




回答4:


You would use:

+ (UIFont *)boldSystemFontOfSize:(CGFloat)fontSize

If you provided a custom font or are using a system-provided font, you'd use the bold typeface as the name of the font:

[UIFont fontWithName:@"Arial-BoldMT" size:17];


来源:https://stackoverflow.com/questions/8888328/how-to-create-bold-uifont

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!