ios 如何在笔尖/故事板的 UITextView 中创建新行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9019527/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a new line in UITextView in nib/storyboard?
提问by t3hcakeman
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.
我试图在 Xcode 4.2 UITextView 中创建一个新行,当我执行 alt+return 时,它转到下一行,但在构建和运行时不显示。
回答by Graham Perks
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.
- 拖出一个
UITextView
. - 双击它以编辑文本,将光标放在您想要分段符的位置。
- Option-输入几次以创建一个空行和段落。
The paragraph shows at runtime. There's also a Text attribute that can be edited in the Attributes inspector.
该段落在运行时显示。还有一个可以在属性检查器中编辑的 Text 属性。
回答by Michal Zaborowski
ALT+ Entermakes a new line in storyboard
ALT+Enter在故事板中新建一行
回答by Darren
In the attributes inspector, there is property 'Lines' to set how many lines of text. Change it to 2.
在属性检查器中,有属性 'Lines' 来设置文本的行数。将其更改为 2。
回答by FranMowinckel
This is a workaround, but it works everytime and also for UILabels which is more interesting:
这是一种解决方法,但它每次都有效,也适用于更有趣的 UILabels:
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.
只需打开文本编辑器(例如 textEdit 或 XCode 本身),根据需要使用新行写入文本,然后将粘贴复制到界面构建器中的标签文本属性中。它同时显示在界面构建器和运行时中。
回答by Simon Barkhuizen
- (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.
假设您在 (.h) 文件中创建了“theTextView”并将其合成在 (.m) 文件中并进行了适当的连接。
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?
如果您告诉 al wen 必须准确地制作新行,我可以给出更明确的答案...以编程方式用户按下按钮的时间?
回答by Adi
Drag a view (resize to a line) and add it a background color. I'm not sure if there's another way.
拖动一个视图(调整为一条线)并为其添加背景颜色。我不确定是否还有其他方法。