PDA

View Full Version : How can I add a CRLF to a label?




danmwall
Apr 18, 2009, 11:18 PM
I have a label that is set to wrap to multiple lines. I am setting the text in the code using setText, but it is rather long and I would like to break it up to make it easier to read. Is there a way to insert a carriage return/line feed? For example:

[sampleText setText:@"This text is pretty long. I would like a CRLF here. See, isn't this easier to read now?"];

Seems like it should be simple enough...



CocoaPuffs
Apr 18, 2009, 11:20 PM
I have a label that is set to wrap to multiple lines. I am setting the text in the code using setText, but it is rather long and I would like to break it up to make it easier to read. Is there a way to insert a carriage return/line feed? For example:

[sampleText setText:@"This text is pretty long. I would like a CRLF here. See, isn't this easier to read now?"];

Seems like it should be simple enough...
set the number of lines to be shown in label attribute, and then use \n as line breaker.

danmwall
Apr 20, 2009, 09:17 AM
Duh! Of course! You would think I would have tried that! Thanks, it works like a charm!

Guiyon
Apr 20, 2009, 11:22 PM
[sampleText setText:@"This text is pretty long. I would like a CRLF here. See, isn't this easier to read now?"];

Being nit-picky here but, simply for information's sake, using CRLF (\r\n) as a line/section break is limited mostly to ASCII-based comm protocols and Windows. The POSIX world (Mac OS X, Linux, *BSD, etc.) all use just an LF (\n) while Classic Mac OS used CR (\r).