47

I have a simple app with a UITextView embedded into a UIScrollView. Interface Builder won't let me add multiple newlines for spacing; when I hit return it sees that as "end of input" rather than appending the newline to the UITextView.

How can I get it to accept newlines for spacing?

Quinn Taylor
  • 44,553
  • 16
  • 113
  • 131
George Armhold
  • 30,824
  • 50
  • 153
  • 232

4 Answers4

147

Much simpler (and more IB based) than previous answers:

Just Alt + ENTER It will send a newline to the UITextView.

carbonr
  • 6,049
  • 5
  • 46
  • 73
Aviad Ben Dov
  • 6,351
  • 2
  • 34
  • 45
  • 1
    Good to know. I never even tried that. I tried the normal Shift-Enter, but it does nothing. Ctrl-Enter appears to work (the inspector shows blank lines), but it isn't respected in the view. – Oscar May 27 '11 at 07:35
  • 1
    Works for UILabels with number of lines set to 0 as well. – Nick Jun 24 '11 at 17:36
  • At the first three tries ALT+Enter didn't work. But after some backspacing and adding ALT+Enter to a couple of lines it started woking. MAN I have been looking for this answer in a lot of articles :-) – esbenr Mar 02 '12 at 10:15
  • 2
    the fundamental question is how did you find this :) – 2cupsOfTech Jun 07 '12 at 08:36
  • By mistake :-) Actually, it's something I try from time to time with text boxes, you'll see that in many cases where there is a multi-line text box that takes Enter key as the "Done" idiom, it will have some sort of key combination (usually ALT+Enter) for "next line". – Aviad Ben Dov Jun 29 '12 at 14:29
  • _works like magic_ [try this](http://stackoverflow.com/a/21654430/3577656) – Rajal Oct 20 '16 at 12:38
10

Write up your text in TextEdit, then copy/paste it in.

Simon Woodside
  • 7,175
  • 5
  • 50
  • 66
2

As sbwoodside said, a text editor is the easiest way.

That said, ff you need more control, or it isn't quite working, don't use IB. Ideally, if you need any type of formatting for a long sting of text, do it programmatically.

Formatting in IB is horrible. I tried to add some "terms and conditions" in a UITextView and it was a real pain.

In the end it is easier than messing with IB...

Corey Floyd
  • 25,929
  • 31
  • 126
  • 154
1

In IB Shift+Alt (Option)+Enter is as New paragraph

Bimawa
  • 3,535
  • 2
  • 25
  • 45
  • 1
    For me the ALT+Enter wasn't working... it would reflect the newline in the IB editor but the actual display wouldn't work. Your key combination did exactly what I needed. Thanks! – Art Geigel Apr 02 '13 at 06:59