I have made a Button which generates TextFields and I want a ScrollView so if I'd add too much TextFields I could scroll and write to them. I also have a Button at the bottom of my view and I want this to be visible all the time. (I don't mind if only TextFields will be inside the ScrollView or the whole view except my bottom button).
-
so what have you done so far? can you show us the code?Ozgur Vatansever– Ozgur Vatansever2016-10-28 19:56:27 +00:00Commented Oct 28, 2016 at 19:56
-
I don't have something for the scrollview. I don't know what is better to put it from storyboard or code?mike vorisis– mike vorisis2016-10-28 19:58:22 +00:00Commented Oct 28, 2016 at 19:58
2 Answers
You have to set the height constraint on your TextFields. Without that, the scrollView can't figure out its contentSize. After you set the heights, the scrollView will adapt accordingly.
Also, I would use a UIView and give a fix height for it and place the TextFields inside of the UIView.
You can also use scrollView.contentSize = CGSize(width: expectedWidth, height: expectedHeight)
3 Comments
These steps help you to design screen according to your requirement :
- Drag a
ScrollViewand provide height and width accordingly - Decrease height of ScrollView by height of Button which you always want to show on bottom of page
i.e- Button should be outside of
ScrollViewnot within theScrollView - Adjust button size and height and put it below to
ScrollView - Now set Constraint to each one . First of all select
ScrollViewprovide its l Left , Right , Top constraint . - Select
ScrollViewand by pressingControl + drag mouseto Button ( below of Scrollview) and set vertical spacing between ScrollView and Button - Select Button and provide Left , Right , Bottom Constraint.
Note - As AutoLayout works differently with ScrollView so always set constraint of all control within it from Order : Top To Bottom
Hope it helps you to fix this issue . Feel free to comment if still any confusion.
Thanks.
