How to make a new line in UITextView in nib/storyboard?
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?
t3hcakeman
Updated on August 19, 2020Comments
-
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 over 12 yearsI didn't do any of this programmatically. This was all done in storyboard.
-
Darren over 12 yearsSorry, I was thinking UILabel
-
t3hcakeman over 12 yearsThere is no Lines property. This is storyboard.
-
t3hcakeman over 12 yearsThis doesn't work for all of them. I have about 10 UITextViews, all copy pasted, and some work, some dont.
-
Darren over 12 yearsThere is for a label. Sorry I didn't realize you meant TextView.
-
Graham Perks over 12 yearsWhat happens in the ones that don't work? Are they differently sized?
-
Patrick almost 12 yearsIn 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 almost 9 yearsTry 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 almost 9 yearsIn the attributes inspector set property 'Lines' to 0 to have multiline label/text field.
-
Rajal over 7 yearsworks like magic try this
-
Adam Johns over 4 yearsDon't forget to press 'enter' after done adding the newlines like me :)