Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

\n not working in UIlabel

I've seen similar questions here, but still can figure out why it's not working.

How to add line break (in other words add new paragraph) in multiline UIlabel?

I have a label with a lot of text,

lbl.numberOfLines = 0;
lbl.sizeToFit;

but I'm still getting something like this: "Some text here\nAnd here I want new line"

Thank you

like image 750
Burjua Avatar asked Aug 05 '10 16:08

Burjua


2 Answers

This is an old question, but just wanted to let you know that \r works like a charm :)

like image 89
Filip Valentin Avatar answered Nov 03 '22 00:11

Filip Valentin


UILabel won't respect \n, You can use option-return (in Interface builder) to force where you want a line break.

You can use a UIWebView in place of the label and then you can format however you like. (And set the lineBreakMode as AngeDeLaMort says above.)

like image 27
joelm Avatar answered Nov 03 '22 00:11

joelm