I want to insert 2 lines for a UILabel
like this
$2500.50
per ride
I need to add these two lines into a same UILabel
programmatically. How can I do that. Please anybody help me.
Thanks
I want to insert 2 lines for a UILabel
like this
$2500.50
per ride
I need to add these two lines into a same UILabel
programmatically. How can I do that. Please anybody help me.
Thanks
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.
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];