ios 如何在标签中写多行

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

How to write multiple lines in a label

iosobjective-ccocoa-touchinterface-builder

提问by Lea Cohen

I have a XIB file of type View XIB. In it I have a View controller, and in the View controller I have a label.
I have long text that I want to break, but it doesn't - it gets truncated.
I tried this solution- I did it in the attribute window - but it doesn't help.

我有一个查看 XIB 类型的 XIB 文件。在其中我有一个视图控制器,在视图控制器中我有一个标签。
我有很长的文本想要打破,但它没有 - 它被截断了。
我尝试了这个解决方案- 我在属性窗口中做到了 - 但它没有帮助。

回答by Ferruccio

You could use a TextView and disable the Editableand User Interaction Enabledoptions in IB.

您可以使用 TextView 并禁用IB 中的EditableUser Interaction Enabled选项。

回答by Samueljt

use this

用这个

myLabel.lineBreakMode = UILineBreakModeWordWrap;

if you are worried about backwards compatibility use this because the comand i mentioned before was introduced in iOS 6.0

如果您担心向后兼容性,请使用它,因为我之前提到的命令是在 iOS 6.0 中引入的

myLabel.numberOfLines = 0;

回答by Boeckm

I have been running into a similar problem. I started out with a label, but wanted multi-lines and a UITextViewworked great for this, at first. Because I am using a third party library (MBProgressHUD) to handle stuff like progress messages and what not, I had thread problems when trying to update a UITextViewand show the progress message at the same time.

我遇到了类似的问题。我从一个标签开始,但UITextView起初想要多行并且非常适合这个。因为我使用第三方库 ( MBProgressHUD) 来处理诸如进度消息之类的东西,所以我在尝试更新 aUITextView并同时显示进度消息时遇到了线程问题。

So I went back to UILabelwhich actually didn't have thread problems. I found a property to allow a specific number of lines of my choosing, and had to create the label big enough to display those lines. The downfall to this approach is that I don't get the context menus like Copy, Paste, etc. but more importantly I'm not running into thread problems. I can always embed this into a UIScrollViewin the future if I so choose.

所以我回到UILabel实际上没有线程问题的地方。我找到了一个属性来允许我选择特定数量的行,并且必须创建足够大的标签来显示这些行。这种方法的缺点是我没有得到像复制、粘贴等这样的上下文菜单,但更重要的是我没有遇到线程问题。UIScrollView如果我愿意,我可以随时将其嵌入到 a中。

回答by Daniel

You could check out my category for UILabel on GitHub. https://gist.github.com/1005520

您可以在 GitHub 上查看我的 UILabel 类别。https://gist.github.com/1005520

This lets you resize the height of the label to accommodate the content.

这使您可以调整标签的高度以适应内容。

回答by Lyubomir Velchev

From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. Also increase the number of lines Label->Lines.

选择标签后,从属性检查器中选择 LineBreaks->Word Wrap 选项。还要增加 Label->Lines 的行数。

回答by Mandar Choudhary

Try Following steps to solve issue :

尝试按照以下步骤解决问题:

  • 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-输入几次以创建一个空行和段落。