How to make a new line in UITextView in nib/storyboard?

37,140

Solution 1

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.

Solution 2

ALT + Enter makes a new line in storyboard

Solution 3

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

Solution 4

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.

Solution 5

- (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?

Share:
37,140
t3hcakeman
Author by

t3hcakeman

Updated on August 19, 2020

Comments

  • t3hcakeman
    t3hcakeman almost 4 years

    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.

  • t3hcakeman
    t3hcakeman over 12 years
    I didn't do any of this programmatically. This was all done in storyboard.
  • Darren
    Darren over 12 years
    Sorry, I was thinking UILabel
  • t3hcakeman
    t3hcakeman over 12 years
    There is no Lines property. This is storyboard.
  • t3hcakeman
    t3hcakeman over 12 years
    This doesn't work for all of them. I have about 10 UITextViews, all copy pasted, and some work, some dont.
  • Darren
    Darren over 12 years
    There is for a label. Sorry I didn't realize you meant TextView.
  • Graham Perks
    Graham Perks over 12 years
    What happens in the ones that don't work? Are they differently sized?
  • Patrick
    Patrick almost 12 years
    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.
  • Borzh
    Borzh almost 9 years
    Try not to use it. This will create special character <U+2028>. 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
    Borzh almost 9 years
    In the attributes inspector set property 'Lines' to 0 to have multiline label/text field.
  • Rajal
    Rajal over 7 years
    works like magic try this
  • Adam Johns
    Adam Johns over 4 years
    Don't forget to press 'enter' after done adding the newlines like me :)