问题描述
我创建在Interface Builder一个简单的视图设置。下面是它的外观:
I've created a simple view setup in interface builder. Here's how it looks:
视图层次很简单:
view
- scrollView
-- label
滚动视图显示与锚定在其超视图顶部的灰色
的背景下,前置,并与0约束底部
The scroll view is shown with grey
background anchored to its super view top, leading, trailing, and bottom with constraints of 0.
标签显示为黄
背景,如图所示有限制。此外,该标签具有内容拥抱优先
1000
的水平和垂直,它有 1000
的水平和垂直。
The label is shown with yellow
background and has constraints as shown. Additionally, the label has content hugging priority
of 1000
for both horizontal and vertical, and it has content compression resistance priority
of 1000
for both horizontal and vertical.
在纵向,标签的大小正确:
In portrait orientation, the label is sized correctly:
在横向,然而,标签是不大小正确水平(Ⅰ用于标签以填充屏幕的宽度,小于约束插图所示):
In landscape orientation, however, the label is not sized correctly horizontally (I intended for the label to fill the width of the screen, less constraint insets as shown):
我怎么能在横向水平正常得到这个标签的大小?
How can I get this label to size correctly horizontally in landscape orientation?
推荐答案
有是给你一个解决方案。
There is one solution for you.
1 您的UIScrollView零限制加入的容器的(UIView的):
1. Add your UIScrollView to container (UIView) with zero constraints:
2 添加约束标签:。顶部,底部,领先,尾部的空格= 20
2. Add constraints for Label: top, bottom, leading, trailing spaces = 20.
3 添加约束: label.width = container.width - 40
- 对于这一点,在视图结构树中选择标签,点击CTRL拉
集装箱。并选择宽度相等。
- 然后选择创建的约束,去它的实用程序和设置
恒值40。
您应该得到以下组件:
You should get the following components:
运行应用程序,进入景观和它的作品!
Run the app, go to landscape and it works!
希望这是显而易见的。最好的问候。
Hope it is clear. Best Regards.
这篇关于里面的UIScrollView正确尺寸的UILabel使用Interface Builder和自动布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!