简体   繁体   English

使scrollview的内容适合scrollview超级视图

[英]Fit content of a scrollview to the scrollview superview

I have the following view hierarchy : 我有以下视图层次结构:

View1 (root view)
 Scrollview
  View2

I use auto-layout and I would like the view2 to fit to the view1 size. 我使用自动布局,我希望view2适应view1的大小。 In the past, to solve ambiguous scrollable content, I programmatically added a fixed constraint for the view2 width and height. 过去,为了解决模糊的可滚动内容,我以编程方式为view2的宽度和高度添加了固定的约束。 But I would like to know there is a nicer way to do it. 但我想知道有一种更好的方法。

It is actually quite simple. 实际上很简单。 Set two constraints linking View2 and Scrollview ( Superview actually) with Equal Widths and Equal Heights . 设置两个约束,以将View2Scrollview (实际上是Superview )与Equal WidthsEqual Heights This can be done in the xib file or programmatically. 这可以在xib文件中或以编程方式完成。

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

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