我有这个代码:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 40)];
label.text = @"I am learning Objective-C for the\n very first time!";
[self.view addSubview:label];
但由于某种原因,它没有插入新行......我如何在一个换行符中插入一个UILabel
?
我有这个代码:
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 40)];
label.text = @"I am learning Objective-C for the\n very first time!";
[self.view addSubview:label];
但由于某种原因,它没有插入新行......我如何在一个换行符中插入一个UILabel
?
请检查
UILabel *yourLabel;
yourLabel.numberoflines = 0
或不..
如果不是这样,请将其设置为零
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 40)];
label.text = @"I am learning Objective-C for the\n very first time!";
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
[self.view addSubview:label];`
我尝试了各种不同的解决方案来在我的 UILabel 中换行。
\r 会成功的!例如:
NSString *detailInfo=[NSString stringWithFormat:@"Address:\r%@", self.aAddress.text];
与@JanB 的解决方案相比,另一种解决方案是,您可以在格式化字符串中插入一个NSString
对象:@"\n"
在您的示例中:
label.text = [NSString stringWithFormat:@"I am learning Objective-C for the%@ very first time!", @"\n"];
让我知道是否有问题:)