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.
我有一个View XIB类型的XIB文件。在其中我有一个View控制器,在View控制器中我有一个标签。我有很长的文本,我想打破,但它没有 - 它被截断。我试过这个解决方案 - 我在属性窗口中做到了 - 但它没有帮助。
6 个解决方案
#1
15
You could use a TextView and disable the Editable and User Interaction Enabled options in IB.
您可以使用TextView并禁用IB中的可编辑和用户交互启用选项。
#2
7
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;
#3
3
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. 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.
我遇到了类似的问题。我从一个标签开始,但想要多行,并且UITextView起初对此非常有用。因为我正在使用第三方库(MBProgressHUD)来处理诸如进度消息之类的东西,所以当我尝试更新UITextView并同时显示进度消息时,我遇到了线程问题。
So I went back to UILabel
which 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 UIScrollView
in the future if I so choose.
所以我回到UILabel,实际上没有线程问题。我找到了一个允许我选择的特定行数的属性,并且必须创建足够大的标签来显示这些行。这种方法的缺点是我没有得到复制,粘贴等上下文菜单,但更重要的是我没有遇到线程问题。如果我愿意的话,我可以在将来将它嵌入到UIScrollView中。
#4
2
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.
这使您可以调整标签的高度以适应内容。
#5
1
From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. Also increase the number of lines Label->Lines.
从Attiribute检查器中,选择lablel后,选择LineBreaks-> Word Wrap选项。还要增加Label-> Lines的行数。
#6
0
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。
双击它以编辑文本,将光标放在您想要段落的位置。
选项 - 输入几次以创建空白行和段落。
#1
15
You could use a TextView and disable the Editable and User Interaction Enabled options in IB.
您可以使用TextView并禁用IB中的可编辑和用户交互启用选项。
#2
7
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;
#3
3
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. 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.
我遇到了类似的问题。我从一个标签开始,但想要多行,并且UITextView起初对此非常有用。因为我正在使用第三方库(MBProgressHUD)来处理诸如进度消息之类的东西,所以当我尝试更新UITextView并同时显示进度消息时,我遇到了线程问题。
So I went back to UILabel
which 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 UIScrollView
in the future if I so choose.
所以我回到UILabel,实际上没有线程问题。我找到了一个允许我选择的特定行数的属性,并且必须创建足够大的标签来显示这些行。这种方法的缺点是我没有得到复制,粘贴等上下文菜单,但更重要的是我没有遇到线程问题。如果我愿意的话,我可以在将来将它嵌入到UIScrollView中。
#4
2
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.
这使您可以调整标签的高度以适应内容。
#5
1
From the Attiribute inspector, choose LineBreaks->Word Wrap option when you have selected the lablel. Also increase the number of lines Label->Lines.
从Attiribute检查器中,选择lablel后,选择LineBreaks-> Word Wrap选项。还要增加Label-> Lines的行数。
#6
0
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。
双击它以编辑文本,将光标放在您想要段落的位置。
选项 - 输入几次以创建空白行和段落。