Ios 如何将两行字符串添加到同一个UILabel中
我想像这样为Ios 如何将两行字符串添加到同一个UILabel中,ios,ios7,uilabel,Ios,Ios7,Uilabel,我想像这样为ui标签插入两行 UILabel *myLabel = [[UILabel alloc] init]; [myLabel setFrame:CGRectMake(20, 20, 300, 200)]; myLabel.lineBreakMode = NSLineBreakByWordWrapping; myLabel.numberOfLines = 2; [myLabel setText:[NSString stringWithFormat:@"%@\n%@", @"$2500.5
ui标签插入两行
UILabel *myLabel = [[UILabel alloc] init];
[myLabel setFrame:CGRectMake(20, 20, 300, 200)];
myLabel.lineBreakMode = NSLineBreakByWordWrapping;
myLabel.numberOfLines = 2;
[myLabel setText:[NSString stringWithFormat:@"%@\n%@", @"$2500.50", @"per ride"]];
[self.view addSubview:myLabel];
2500.50美元
每程
我需要以编程方式将这两行添加到相同的UILabel
。我该怎么做呢。请任何人帮帮我
谢谢可以这样实现:
UILabel *myLabel = [[UILabel alloc] init];
// allows the UILabel to wrap text across multiple lines
myLabel.lineBreakMode = UILineBreakModeWordWrap;
// allows the UILabel to display an unlimited number of lines
myLabel.numberOfLines = 0;
您可以使用新行字符(“\n”)将换行符添加到文本中,如上面的注释所述。您只需要设置一些如下属性
UILabel *myLabel = [[UILabel alloc] init];
[myLabel setFrame:CGRectMake(20, 20, 300, 200)];
myLabel.lineBreakMode = NSLineBreakByWordWrapping;
myLabel.numberOfLines = 2;
[myLabel setText:[NSString stringWithFormat:@"%@\n%@", @"$2500.50", @"per ride"]];
[self.view addSubview:myLabel];
你可以像这样使用@“$2500.50\n骑行后”是的,使用转义字符\n。如@CoolMonster所述