的UILabel文本中未包装纸 [英] UILabel Text Not Wrapping

查看:141
本文介绍了的UILabel文本中未包装纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作与我想要的文本在包装标签故事板一个项目雨燕。在旧的Objective-C版本,我没有用一个Storyboard我用下面的设置和东西完美。

I am working on a Swift project with Storyboards where I want text to wrap in a label. In the old Objective-C version where I did not use a Storyboard I used the following settings and things worked perfectly.

下面是斯威夫特的设置

我一直在阅读关于使用$ P $潜在的汽车布局问题pferred宽度设置。我公司目前将其设置为自动布局和标签本身被设置为560的宽度我添加了一个约束条件,以保持标签从尾随的SuperView 20像素,而我认为这会工作,我仍然不能得到文本包。尺寸设置如下。

I have been reading about the potential auto layout issues with preferred width settings. I currently have them set to auto layout and the label itself is set to a width of 560. I've added a constraint to keep the label 20 pixels from the trailing superview and while I thought this would work I still cannot get the text to wrap. The dimension settings are below.

有人能解释如何获取文本换行?

Can someone explain how to get the text to wrap?

推荐答案

首先,好消息:你的标签设置为2线和自动换行。因此,它的可以的包装。优秀的。

First, the good news: You have set the label to 2 lines and Word Wrap. So it can wrap. Excellent.

现在你必须确保标签是足够高。要么给它的没有的高度约束,或者给它一个足够大的高度约束,它可以容纳两行。

Now you must make sure the label is tall enough. Either give it no height constraint, or give it a big enough height constraint that it can accommodate two lines.

最后,必须的限制了它的宽度的。这是什么原因造成的文本换行。如果您不限制标签的宽度,它只会继续增长向右,可能继续关闭屏幕。标签上的宽度的限制停止这种向右增长,并导致自动换行(和向下发展,而不是标签)。

Finally, you must limit its width. This is what causes the text to wrap. If you don't limit the label's width, it will just keep growing rightward, potentially continuing off the screen. The limit on the label's width stops this rightward growth and causes the text to wrap (and the label to grow downward instead).

您可以通过多种方式限制宽度。你可以有一个实际宽度的限制。或者,你可以有一个主要的约束和制约尾随,要东西比较不动产,如上海华。还有第三种方式:在尺寸检查(这你也表明,你的问题的右下角),设置preferred宽度(它显示在尺寸督察的顶部):这是宽度其中,所有其他的事情都是平等的,标签将停止生长的权利和包裹和成长,而不是下降。

You can limit width in several ways. You can have an actual width constraints. Or you can have a leading constraint and a trailing constraint, to something relatively immovable, such as the superview. And there is a third way: on the Size inspector (which you do also show, at the bottom right of your question), set the Preferred Width (it is shown at the top of the Size inspector): this is the width at which, all other things being equal, the label will stop growing to the right and wrap and grow down instead.

这篇关于的UILabel文本中未包装纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆