Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UILabel:如何设置字体大小?_Ios_Objective C - Fatal编程技术网

Ios UILabel:如何设置字体大小?

Ios UILabel:如何设置字体大小?,ios,objective-c,Ios,Objective C,如何从UILabel设置字体大小 我的代码: UILabel *myView = [[UILabel alloc] initWithFrame:RectFrame]; [myView setBackgroundColor:[UIColor blueColor]]; [myView setText:[NSString stringWithFormat:@" A"]]; [myView setFont:[12] ]; <--- Error [self.view addSubview:myVie

如何从
UILabel
设置字体大小

我的代码:

UILabel *myView = [[UILabel alloc] initWithFrame:RectFrame];
[myView setBackgroundColor:[UIColor blueColor]];
[myView setText:[NSString stringWithFormat:@" A"]];
[myView setFont:[12] ]; <--- Error
[self.view addSubview:myView];
UILabel*myView=[[UILabel alloc]initWithFrame:RectFrame];
[myView setBackgroundColor:[UIColor blueColor]];
[myView setText:[NSString stringWithFormat:@“A”];
[myView setFont:[12]] 检查课程。之后,您可能会明白为什么要这样使用它:

[myView setFont:[UIFont systemFontOfSize:12]];

或字体系列

[myView setFont:[UIFont fontWithName:@"Helvetica" size:12]];

请记住,用户可以全局设置他们希望文本的大小,因此不应使用固定的字体大小,如“12”。使用以下字体:

[UIFont preferredFontForTextStyle:UIFontTextStyleHeadline]

[UIFont preferredFontForTextStyle:UIFontTextStyleBody]
[UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
[UIFont preferredFontForTextStyle:UIFontTextStyleFootnote]
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1]
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption2]

我认为UILabel的默认值是Caption1,其他的会更大或更小。如果用户希望在其设备上显示大文本或小文本,它们将进行调整。(如果用户选择非常小的字体,则字体大小12实际上可能大于正常标签大小)

如果您的
UILabel
的字体是在
IB
情节提要中定义的,并且您只想增加大小,那么这将起作用,对我来说是有效的;)

其他人所说的另一种方法也有效:

[_label setFont:[UIFont systemFontOfSize:13.0]];
迅速地

yourLabel.font = UIFont(name:"name of font-family you want", size: 9)
Swift 4及以上

你也可以试试

label.font = UIFont.systemFont(ofSize: 10) 

你能解释一下吗?
[_label setFont: [_label.font fontWithSize: sizeYouWant]];
[self.label setFont: [self.label.font fontWithSize: sizeYouWant]];
[_label setFont:[UIFont systemFontOfSize:13.0]];
yourLabel.font = UIFont(name:"name of font-family you want", size: 9)
label.font = UIFont.systemFont(ofSize: 10)