我有这段代码:
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
中添加换行符?
答案 0 :(得分:11)
请检查
UILabel *yourLabel;
yourLabel.numberoflines = 0
与否..
如果不是这样,请将其设置为零
答案 1 :(得分:3)
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];`
答案 2 :(得分:3)
我尝试了各种不同的解决方案,以便在我的UILabel中获得换行符。
\ r将会做到这一点!例如:
NSString *detailInfo=[NSString stringWithFormat:@"Address:\r%@", self.aAddress.text];
答案 3 :(得分:0)
与@ JanB相比,另一个解决方案是,您可以在格式化字符串中插入NSString
对象:@"\n"
:
在你的例子中:
label.text = [NSString stringWithFormat:@"I am learning Objective-C for the%@ very first time!", @"\n"];
让我知道是否有问题:)