简体   繁体   中英

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

我正在尝试在Xcode 4.2 UITextView中创建一个新行,当我执行alt + return时,它会转到下一行,但在构建和运行时不显示。

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.

ALT + Enter在故事板中创建一个新行

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

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

Just open a text editor (eg 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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM