ios 如何从在 IB 中输入的 UILabel 文本中插入新行 \n?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15444981/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:45:33  来源:igfitidea点击:

How to insert new line \n from UILabel text which typed in IB?

iosobjective-cnsstring

提问by Alex

I have id textInput and I insert new line(\n) OK with:

我有 id textInput 并插入新行(\ n)OK:

[textInput insertText:@"\n"];

But when input Text from label.text (Input in Interface Builder) ,it NOT OK. Just input \n text.

但是当从 label.text (Input in Interface Builder) 输入 Text 时,就不行了。只需输入\n 文本。

NSLog(@"%@",label.text);
[textInput insertText:label.text];

How to input special character when store it in label.text?

将特殊字符存储在label.text中时如何输入特殊字符?

I don't want to compare [inputStr isEqualToString:@"\\n"];

我不想比较 [inputStr isEqualToString:@"\\n"];

*Log: \n

*日志:\n

Thanks!

谢谢!

回答by tc.

Try option-return or pasting in the newline.

尝试选项返回或在换行符中粘贴。

回答by Shamsudheen TK

@Hot Licks explained the reason well in comment.

@Hot Licks 在评论中很好地解释了原因。

The only way is

唯一的办法是

if ([self.mylabel.text isEqualToString:@"\n"]) {

   [self.myTextView insertText:@"\n"];
}

Manually, use ALT+ENTER

手动,使用 ALT+ENTER