Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set UIScrollView Height in Swift

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

this is the top of the view

after scrolling (see the blank content after button submit)

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

storyboard 1

storyboard 2

like image 484
christ2702 Avatar asked Jul 25 '17 04:07

christ2702


People also ask

How to change ScrollView height swift?

your_scrollView. frame = CGRect(x: 0, y: 0, width: 375, height: 667) your_scrollView. contentSize = CGSize(width: 375, height: 1000) // You can set height, whatever you want. Save this answer.

How do I set scroll view?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.


1 Answers

1) ScrollView Contraints

enter image description here

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

enter image description here

5) contentView Width Contraint

enter image description here

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

enter image description here

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

enter image description here

and constraints for my DoubleRight imageView are

enter image description here

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

enter image description here

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

enter image description here

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

like image 101
iOS Geek Avatar answered Sep 30 '22 20:09

iOS Geek