Line break in UILabel?

I have this code:

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 40)]; label.text = @"I am learning Objective-C for the\n very first time!"; [self.view addSubview:label]; 

But for some reason it doesn't insert a new line ... how to put a line break in a UILabel ?

+4
source share
4 answers

Please check that

  UILabel *yourLabel; yourLabel.numberoflines = 0 

or not..

if it is not, set it to zero

+11
source
 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(25, 25, 275, 40)]; label.text = @"I am learning Objective-C for the\n very first time!"; label.lineBreakMode = UILineBreakModeWordWrap; label.numberOfLines = 0; [self.view addSubview:label];` 
+3
source

I tried all sorts of solutions to get a new line in my UILabel.

\ r will do the trick! For instance:

 NSString *detailInfo=[NSString stringWithFormat:@"Address:\r%@", self.aAddress.text]; 
+3
source

Another solution compared to @JanB one, you can insert an NSString : @"\n" object in the format string:

In your example:

label.text = [NSString stringWithFormat:@"I am learning Objective-C for the%@ very first time!", @"\n"];

Let me know if there is a problem :)

0
source

All Articles