ios 如何创建粗体 UIFont

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8888328/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:22:04  来源:igfitidea点击:

How to create bold UIFont

iosuitableviewuifont

提问by HurkNburkS

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.

我正在我的 tableview 中做一些自动换行,因为一些值太大了,它们超出了屏幕的边缘。

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

回答by Jesse Black

You can look into the fontNamesForFamilyName:method.

你可以看看fontNamesForFamilyName:方法。

Specifically for Helvetica there are these families

专门为 Helvetica 设计的有这些系列

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

回答by theTRON

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

如果您使用的是 iOS 中捆绑的 Helvetica 版本,您只需执行以下操作:

[UIFont boldSystemFontOfSize:17.0];

回答by danielbeard

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

以下是可用字体列表:http: //www.iphonedevsdk.com/forum/iphone-sdk-development/6000-list-uifonts-available.html

回答by Jesse Bunch

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