Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there is way to embed UIView's in UIScrollview without losing subviews constraints in iOS?

I have too many subviews in my ContentView and now I want this contentView in UIScrollview but if I do that I lose all the subview's constraints. Editor->Embed in UIScrollview is not working.

Is there any way to embed ContentView in UIScrollView ? Thanks

like image 461
Avijit Nagare Avatar asked Feb 16 '16 06:02

Avijit Nagare


3 Answers

Not reliable answer. but fixed by selecting ContentView

Editor->Embed in -> Scroll View

Then Xcode complaining constraints. Clicked on Red button and just selected "Add missing constraints". this fixed for me.

like image 193
Avijit Nagare Avatar answered Sep 29 '22 07:09

Avijit Nagare


Just select your controls now go on Editor->EmbedIn->View

like image 36
Dheeraj Kumar Avatar answered Sep 29 '22 08:09

Dheeraj Kumar


Perhaps a little tricky, so make sure to have a backup of your storyboard/xib, but if you use 'Open as' > 'Source Code' (control click on the file) and find the view in the XML and change both the opening and closing tag from view to scrollView. Now when you do 'Open as' > 'Interface Builder' you got yourself a scroll view instead.

Please note that constraints to the top and bottom of the view default to use the top and bottom layout guides, but if you want it to scroll you need to use top or bottom space to the container view (the scroll view). You can do that by pressing option when creating the constraints.

like image 40
Johan Kool Avatar answered Sep 29 '22 09:09

Johan Kool