Search code examples
iosxcodeswiftautolayoutsize-classes

Xcode 7 Vertical Scroll View Issues


I'm having trouble creating a vertical only scrollview in Xcode 7.3. I've followed a couple of tutorials on SO and other places but for some reason it seems that my topmost view's width extends past the screen or is shifted to the left. The scroll view is restricted to vertical scrolling only, which is my intent but the content appears partially off the screen.

I try to horizontally center buttons and pin to the top and bottom of the content view. On the simulator they appear half off the screen to the left but they appear fine in the storyboard with no constraint issues. I even preview the view 3.5, 4, and 4.7 inch screens in the assistant editor and it looks as I expect it. But when I run it on the simulator it's messed up. Also the background of the Content View is supposed to be white (for testing purposes) but it's showing the gray color of the top-most view.

This is what I do along with pictures of my constraints

  1. Add Scroll View and pin to the super views top, bottom, left, right (0,0,0,0)

  2. Add Content View and pin to Scroll View top, bottom, left, right (0,0,0,0) and also add a constant height of 1000.

  3. I ctrl+drag from Content View to View (parent of Scroll View) and set equal width constraint.

  4. Place 2 buttons inside Content View pin 1 to the top and the other to the bottom. Both are horizontally centered as well.

This is what it looks like on the simulator.

Simulator-Actual

And this is what I its supposed to look like on the iPhone screens.

Storyboard-Expected


Solution

  • Give it horizontal centre constraint and than check