如何使滚动视图本次车展的布局安排工作 [英] How to make this auto layout arrangement work with scrollview

查看:142
本文介绍了如何使滚动视图本次车展的布局安排工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个屏幕布局,其中有两个可调整大小的标签,其中将包含多行文本。这些标签被放置其中的实习生将被添加到主内容查看他们的父母的意见在里面,主要内容查看,然后添加到滚动视图(那是什么大多数解决方案的建议)。对于这两个标签(如下关于与时间和地点标签附着第一图)我已经设置的高度限制为大于或等于和numberOfLines设置为0,以及调用SizetoFit,但并不如预期的实际产出(见附图第二图像)。没有约束的警告。提供了用于所有元件的所有约束

I have a screen layout where there are two resizable labels , which will contain multiline text. These labels are placed inside their parent views which intern are added to main contentView, main contentView is then added to scrollView ( thats what most of the solutions suggests). For both the labels (below About and Time and location labels in first image attached) I have set height constraints as "greater than or equal to" and setting the numberOfLines to 0 as well as calling SizetoFit, but actual output is not as expected (see second image attached). There are no constraints warnings. All constraints are provided for all the elements.

在这里输入的形象描述

在这里输入的形象描述

在viewDidLoad中的code是标签之一,如下所示。

The code in viewDidLoad is as follows for one of the label.

self.lblAbout.text = @"this is a long two three lines about string which will have two lines this is a long two three lines about string which will have two lines";
self.lblAbout.numberOfLines = 0;
[self.lblAbout sizeToFit];
[self.lblAbout setPreferredMaxLayoutWidth:244.0];

此外

-(void)viewDidLayoutSubviews
{
 [super viewDidLayoutSubviews];
 scrollView.contentSize = contentView.frame.size;
}

若需要任何额外的限制,我已经添加了所有前置,顶部,底部随高度的限制以及需要的地方,加上所有的观点之间的间距很到位。
我要的是标签应该得到调整,以线的数量和内容查看(父视图)内滚动型应为滚动的总高度将大于屏幕可用。

Not if any additional constraints are needed, I have added all leading , trailing , top , bottom constrains along with height wherever needed, plus the spacing between all the views is in place. What i want is the labels should get adjusted to number of lines and the contentView (parent view) should scroll inside ScrollView as the total height will be larger than the screen available.

***的问题,我认为是没有得到调整大小按因其中下面的所有意见都没有得到重新定位****标签的标签外视图

*** problem I think is the outer view of the labels aren't getting resized as per the label because of which all the views below it aren't getting repositioned ****

推荐答案

下面是最后的工作。


  1. 添加滚动型主视图

  2. 添加的视图为内容查看(一定要在它的设计师重命名为东西不仅仅是查看)

  3. 滚动型固定使用尾随领先的顶部和底部空间的限制主视图。

  4. 置顶内容查看到滚动型同上

  5. 添加所有组件各自的约束条件

  6. 设置,我想用大于或等于约束(这是必要的),并在code线为0的设置数量调整大小的UILabel的高度

  7. 标签的父视图应该没有任何固定的高度却足以限制在运行时计算。

  8. 确保滚动型在计算contentSize没有含糊。

  9. 小鬼的 - 添加约束主视图,滚动视图的宽度,内容查看(这是在我的情况,你可能不需要内容查看和滚动视图之间的宽度相等的约束,但内容查看其所需的主视图之间)
    现在,滚动型卷轴正是它需要的方式。
    要我相信最上面的东西我已经做了,但不知它不工作,删除一切,几次又做了所有的事情,它的工作。

  1. Added ScrollView in main View
  2. Added View as a contentView ( be sure to rename it in designer to something than just view )
  3. pinned scrollview to main view using leading trailing top and bottom space constraints.
  4. Pinned contentView to scrollview same as above
  5. Added all the components with their respective constraints
  6. Set the height of UILabel which i want to resize using "Greater than or equal to constraint (this is necessary) and set number of lines to 0 in code
  7. The parent view of label shouldn't have any fixed height but enough constraints to calculate it at runtime.
  8. Make sure ScrollView has no ambiguity in calculating contentSize.
  9. imp - Add constraints to width of Main view , scrollview , contentView ( that was in my case , you may not need equal width constraint between contentView and scrollview , but between contentView and main view its necessary) Now scrollview scrolls exactly the way it's needed. To my belief most of the above things i already did but somehow it wasn't working ,deleted everything and did all the things again few times and it worked.

这篇关于如何使滚动视图本次车展的布局安排工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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