Reputation: 4710
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 do I put a line break in an UILabel
?
Upvotes: 4
Views: 12509
Reputation: 495
Another solution compared to @JanB's one, you can insert an NSString
object: @"\n"
into the formatting 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 :)
Upvotes: 0
Reputation: 914
I tried all sorts of different solutions to get a newline in my UILabel.
\r will do the trick! For example:
NSString *detailInfo=[NSString stringWithFormat:@"Address:\r%@", self.aAddress.text];
Upvotes: 3
Reputation: 1889
Please check that
UILabel *yourLabel;
yourLabel.numberoflines = 0
or not..
if it is not like this please set it to zero
Upvotes: 11
Reputation: 2678
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];`
Upvotes: 3