0

I want to insert 2 lines for a UILabellike this

$2500.50

per ride

I need to add these two lines into a same UILabelprogrammatically. How can I do that. Please anybody help me.

Thanks

CoolMonster
  • 2,258
  • 25
  • 50
user2889249
  • 899
  • 2
  • 13
  • 22

2 Answers2

0

This can be achieved like so:

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; 

You can add line breaks to the text using new-line characters (“\n”), as mentioned in the comments above.

Woodstock
  • 22,184
  • 15
  • 80
  • 118
0

You only need to set some properties like this

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];
Fran Martin
  • 2,369
  • 22
  • 19