61

我想让 UILabel 的文字加粗

infoLabel=[[UILabel alloc]initWithFrame:CGRectMake(90,150, 200, 30)];
[infoLabel setText:@"Drag 14 more Flavors"];
[infoLabel setBackgroundColor:[UIColor clearColor]];
[infoLabel setFont:[UIFont fontWithName:@"Arial" size:16]];

[infoLabel setTextColor:[UIColor colorWithRed:193.0/255 
                                        green:27.0/255 
                                         blue:23.0/255 
                                        alpha:1 ]];
4

6 回答 6

131

如果要保留系统字体并使其变为粗体:

[infoLabel setFont:[UIFont boldSystemFontOfSize:16]];
于 2011-01-05T09:57:10.907 回答
68

尝试

[infoLabel setFont:[UIFont fontWithName:@"Arial-BoldMT" size:16]];

检查您尝试使用的字体是否在设备上可用也可能是值得的

于 2011-01-05T09:43:13.940 回答
40

使用 Xcode 中的 GUI 选择标签,然后转到 Attributes Inspector。选项之一是字体。单击字体图标(不是上下箭头)。在出现的弹出窗口中展开字体组合框。在粗体系统部分下选择常规。

Xcode screenshot

于 2015-03-02T19:13:45.833 回答
16

对于 swift 用户,这应该可以工作:

myLabel.font = UIFont.boldSystemFont(ofSize: 12.0)

或者如果您想使用不同的字体:

myLabel.font = UIFont(name:"HelveticaNeue-Bold", size: 12.0)
于 2016-10-25T11:11:01.373 回答
5

Where possible I would suggest using dynamic font sizes to provide the best possible accessibility to your users.

You can make a label use a system dynamic font and set it to have bold text by doing the following:

 exampleLabel.font = UIFont.preferredFont(forTextStyle: .body, compatibleWith: UITraitCollection(legibilityWeight: .bold))
于 2019-12-01T20:23:54.883 回答
0

如果您没有自定义字体的粗体变体,您可以将笔画设置为负值以产生粗体效果。看这里:

我怎样才能用带有 UILabel 的 NSAttributedString 进行描边和填充

于 2015-02-11T18:08:20.417 回答