如何在Swift中设置UIScrollView Height [英] How to set UIScrollView Height in Swift

查看:158
本文介绍了如何在Swift中设置UIScrollView Height的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swift来构建应用程序.我想使用情节提要向我的视图控制器添加一些内容.

我已经将所有内容都放在了滚动视图中并设置了特定的高度,但是,当我运行该应用程序时,滚动视图设置的时间总是长于视图底部的按钮

我希望在按钮后立即停止滚动视图

请好帮我解决这个问题

谢谢

滚动后

作为参考,请忽略评论"和提交"按钮之间的空白,因为实际上它们之间存在UITextView,但不可见(仍尝试添加一些边框)

这些是我的故事板预览

解决方案

1)ScrollView约束

2)ScrollView-> contentView约束滚动查看与上图相同的图片

3)现在ContentView对主视图[嵌入了ScrollView的SuperView]的宽度和高度约束,约束如下.

4)现在单击EqualWidth来查看[顶部第三约束]并按照步骤6进行编辑

5)contentView宽度约束

6)ContentView高度限制//设置优先级[必须].在这里,您需要将菜单中的第一项和第二项更改为如下所示:第一个为-ContentView.Height,第二个为-View.height,并将优先级设置为250,之后这条虚线将沿着contentView出现在故事​​板上. >

7)现在在contentView中添加[UIView,标签,文本字段]之类的内容,并将约束作为top upperMost视图顶部空间添加到contentView [就像我有DoubleRight imageView

和DoubleRight imageView的约束是

在给定顶部空间20分的情况下,查找顶部空间边距

和您将要添加到ContentView中的最后一项一样,就像我有uiView一样

将此视图的底部空间添加到您的superView [ContentView]中,我的约束是:

初始化所有这些步骤后,结果将达到每种屏幕尺寸的预期效果,而无需另外更改屏幕尺寸的高度

注意:-[所有视图必须使用top和bottom参数相互连接]

像Flow一样

View1 - top to contentView and bottom to View2
View2 - top to View1 and bottom to view3
View3 [Last view] - top to View2 and bottom to contentView as shown 

使用uiView,uiimageViews的高度必须固定

I'm using swift to build an application. I want to add some content to my view controller using storyboard.

I already put everything inside the scrollview and set the specific height, but however when I run the application, the scrollview always set longer than the button in the bottom of the view

I want the scroll view stop right after the button

Please kindly help me how to solve this problem

thank you

after scrolling

for your information, please ignore the white space between 'critics' and submit button, because actually there's UITextView between them but not visible (still try to add some border)

these are my storyboard preview

解决方案

1) ScrollView Contraints

2) ScrollView -> contentView Constraints to scroll View same as above image

3) now ContentView width and Height Constraints to main View [SuperView in which ScrollView is embedded] and constraints will be as follows.

4) now click on the EqualWidth to View [Third constraint from top]and edit it as in step 6

5) contentView Width Contraint

6) ContentView Height Constraint // set priority [must] . here you need to change the first item and second item in the menu to as shown First as - ContentView.Height and second as - View.height and set priority to 250 after this a dotted line will appear in storyboard along the contentView

7) now add the content like [UIView, labels, textfields] in contentView and add constraints as Top upperMost view top space to contentView [like I have]DoubleRight imageView

and constraints for my DoubleRight imageView are

look for the Top space margin its given a top space 20 points

and same you need to do for the last item you will be adding in ContentView like I have uiView

add bottom space from this respective view to your superView[ContentView] and my constraints are:

after you had initialed all these steps results will be as Expected for every Screen size no need to change height additionally for screen sizes

Note : - [all the views must be connected to each other with top and bottom parameter]

like Flow will be

View1 - top to contentView and bottom to View2
View2 - top to View1 and bottom to view3
View3 [Last view] - top to View2 and bottom to contentView as shown 

using uiView, uiimageViews their heights must be fixed

这篇关于如何在Swift中设置UIScrollView Height的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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