让我们看看我有一个这样的字符串:
NSString *longStr = @"AAAAA\nBBBBB\nCCCCC";
如何使UILabel像这样显示消息
五星级 BBBBB CCCCC
我不认为\n能被UILabel识别,我能在NSString中放入什么东西让UILabel知道它必须在那里创建换行符吗?
让我们看看我有一个这样的字符串:
NSString *longStr = @"AAAAA\nBBBBB\nCCCCC";
如何使UILabel像这样显示消息
五星级 BBBBB CCCCC
我不认为\n能被UILabel识别,我能在NSString中放入什么东西让UILabel知道它必须在那里创建换行符吗?
当前回答
只是使用标签。numberolines = 0;
其他回答
只是使用标签。numberolines = 0;
//不要忘记将numberolines设置为0
UILabel* locationTitle = [[UILabel alloc] initWithFrame:CGRectMake(5, 30, 230, 40)];
locationTitle.font = [UIFont systemFontOfSize:13.0];
locationTitle.numberOfLines = 0;
locationTitle.text = [NSString stringWithFormat:@"Eaton industries pvt. Ltd \nUK Apr 12"];
[cell addSubview:locationTitle];
对于那些想要一个简单的解决方案的人,请在Interface Builder中的文本标签输入框中执行以下操作:
确保你的行数设置为0。
Alt + Enter
(Alt是你的选项键)
干杯!
textLabel.text = @"\nAAAAA\nBBBBB\nCCCCC";
textLabel.numberOfLines = 3; \\As you want - AAAAA\nBBBBB\nCCCCC
textLabel.lineBreakMode = UILineBreakModeWordWrap;
NSLog(@"The textLabel text is - %@",textLabel.text);
在xCode 11, Swift 5的\n工作良好,尝试以下代码:
textlabel.numberOfLines = 0
textlabel.text = "This is line one \n This is line two \n This is line three"