pretz
pretz

Reputation: 242

ScrollView Won't Scroll - Xcode

I'm new to iOS development and Xcode and am trying to learn. First off, I know there are many posts on this very thing and I would not post unless I was desperate. I have quadruple checked all my constraints after reading many posts, videos and articles. I cannot get my scrollview to scroll. I have included all relevant screenshots but if you need more information I can provide. I am doing all this via storyboard rather than programmatically and would prefer to continue in this manner. Please excuse the repeated horizontal constraints in image 4. They are just a repeat and not duplicate constraints. Thank you!

enter image description here enter image description here enter image description here enter image description here enter image description here

Upvotes: 1

Views: 95

Answers (1)

Chris Comas
Chris Comas

Reputation: 216

To implement a scroll view is very easy here are the steps:

  1. set up a stackView or regular view and input everything you want to be inside that view/stackview (buttons, labels, etc...) -> this is called your "Contentview"

  2. Click on your ContentView and hit "embed in scroll view"

embed button

  1. Click on the scroll view and give it constraints (if you want it to be the full screen -> hit 0 an all 4 sides

constraints window

  1. Open the side panel and click on the scroll view

side panel

  1. Now ctr-drag the ContentView to the Frame-layout-Guide and hit "equal widths" if you want it to scroll up and down (if you want it to scroll left/right -> hit "equal Heights")

scroll view vs contentview

  1. Now ctrl-drag the ContentView to the Content-Layout-Guide and hit
    "top", "leading", "trailing", & "bottom space to content layout guide"

  2. It should be working, if it looks weird, click on the Content-Layout-Guide and go to the size inspector. then make sure that all the constraints are set to 0

size inspector

@seanPatterson also you have have the view as "freeform", you want it to be "inferred"

Upvotes: 1

Related Questions