【问题标题】:How to add two lines of strings into a same UILabel如何将两行字符串添加到同一个UILabel中
【发布时间】:2014-04-05 17:19:32
【问题描述】:

我想像这样为UILabel插入两行

$2500.50

每次骑行

我需要以编程方式将这两行添加到同一个UILabel中。我怎样才能做到这一点。请任何人帮助我。

谢谢

【问题讨论】:

标签: ios ios7 uilabel


【解决方案1】:

你只需要像这样设置一些属性

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];

【讨论】:

    【解决方案2】:

    可以这样实现:

    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”)在文本中添加换行符,如上面的 cmets 中所述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-13
      • 2014-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-17
      相关资源
      最近更新 更多