64

I am trying to make a new line in Xcode 4.2 UITextView, and when I do alt+return, it goes to the next line, but does not show up when built and ran.

Blaszard
  • 30,954
  • 51
  • 153
  • 233
t3hcakeman
  • 2,289
  • 4
  • 25
  • 27
  • If you dont see any paragraph set Word Wrap like here : http://stackoverflow.com/questions/30679370/swift-uibutton-with-two-lines-of-text – Nex Aug 16 '16 at 13:31

6 Answers6

143

This works, I'm unsure what you are doing differently.

  • Drag out a UITextView.
  • Double-click it to edit text, place cursor where you want the paragraph break.
  • Option-Enter a couple of times to create a blank line & paragraph.

The paragraph shows at runtime. There's also a Text attribute that can be edited in the Attributes inspector.

shim
  • 9,289
  • 12
  • 69
  • 108
Graham Perks
  • 23,007
  • 8
  • 61
  • 83
45

ALT + Enter makes a new line in storyboard

Naveed Ahmad
  • 6,627
  • 2
  • 58
  • 83
Michal Zaborowski
  • 5,039
  • 36
  • 35
  • 9
    Try not to use it. This will create special character . If you Open storyboard as Source Code the same editor deletes them, so you will need to edit all labels with line break again (XCode 6.3.1). Use Alt + Enter. – Borzh Jun 03 '15 at 15:29
  • it is Option + Return – iamjpsharma Nov 10 '22 at 06:20
3

This is a workaround, but it works everytime and also for UILabels which is more interesting:

Just open a text editor (e.g. textEdit or XCode itself), write the text with the new lines as desired, and copy paste into the Label text property in Interface builder. It shows in both, interface builder and runtime.

FranMowinckel
  • 4,233
  • 1
  • 30
  • 26
3

In the attributes inspector, there is property 'Lines' to set how many lines of text. Change it to 2.

Darren
  • 10,182
  • 20
  • 95
  • 162
1
- (void)viewDidLoad
{
    [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

   //Note: the \n created a new line.
   //This piece of code assumes there IS ALREADY text in the theTextView
    self.theTextView.text = [[NSString alloc] initWithFormat:@"%@ \n\n a line appart",self.theTextView.text];
}

Assuming you created the "theTextView" in the (.h) file and synthesized it in the (.m) file and made the appropriate connection.

I can give a more clear answer if you tell al wen exactly the new line must be made... Programmatically of when the user presses buttons?

Simon Barkhuizen
  • 846
  • 1
  • 9
  • 18
  • I didn't do any of this programmatically. This was all done in storyboard. – t3hcakeman Jan 26 '12 at 15:03
  • In my experience it is far more reliable to programmatically add text to a textview (if new lines are required) like this. It only takes a few seconds anyway. – Patrick Aug 08 '12 at 14:20
0

Drag a view (resize to a line) and add it a background color. I'm not sure if there's another way.

shim
  • 9,289
  • 12
  • 69
  • 108
Adi
  • 1,263
  • 1
  • 13
  • 24