简体   繁体   English

如何在标签中写入多行

[英]How to write multiple lines in a label

I have a XIB file of type View XIB. 我有一个View XIB类型的XIB文件。 In it I have a View controller, and in the View controller I have a label. 在其中我有一个View控制器,在View控制器中我有一个标签。
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. 我试过这个解决方案 - 我在属性窗口中做到了 - 但它没有帮助。

您可以使用TextView并禁用IB中的可编辑用户交互启用选项。

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;

I have been running into a similar problem. 我遇到了类似的问题。 I started out with a label, but wanted multi-lines and a UITextView worked great for this, at first. 我从一个标签开始,但想要多行,并且UITextView最初对此非常UITextView 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 UITextView and show the progress message at the same time. 因为我正在使用第三方库( MBProgressHUD )来处理诸如进度消息等内容,所以在尝试更新UITextView并同时显示进度消息时遇到了线程问题。

So I went back to UILabel which actually didn't have thread problems. 所以我回到UILabel ,实际上没有线程问题。 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 UIScrollView in the future if I so choose. 如果我愿意的话,我可以在将来将它嵌入到UIScrollView中。

You could check out my category for UILabel on GitHub. 你可以在GitHub上查看我的UILabel类别。 https://gist.github.com/1005520 https://gist.github.com/1005520

This lets you resize the height of the label to accommodate the content. 这使您可以调整标签的高度以适应内容。

From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. 从Attiribute检查器中,选择lablel后,选择LineBreaks-> Word Wrap选项。 Also increase the number of lines Label->Lines. 还要增加Label-> Lines的行数。

Try Following steps to solve issue : 尝试按照以下步骤解决问题:

  • Drag out a UITextView. 拖出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. 选项 - 输入几次以创建空白行和段落。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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