James Fazio
James Fazio

Reputation: 6450

iOS fixed width ScrollView

I want to achieve the following with auto layout.

---------------------
|                   |
|                   |
|                   |
|    ScrollView     |
|                   |
|                   | 
|                   |
|                   | 
---------------------
|                   |
|     Content       |
|                   |
---------------------

The ScrollView has a width equal to the screen size and the content inside the ScrollView extends the screen. I do not want the user to be able to scroll horizontally.

I have tried

  1. Put a View inside of the ScrollView and set both of them to have leading, trailing, top, and bottom constraints to 0. Then I try to dynamically set the width of the Content and ScrollView to the ScreenSize.

  2. Simply surround my page's content in a ScrollView set it to have leading, trailing, top, and bottom constraints to 0. Then I try to dynamically set the width of the ScrollView to the ScreenSize.

Both of the following result in something like this...

enter image description here

Notice how everything is centered horizontally like I have set it up to be, yet the horizontal scrollbar is present and you can scroll into a blank screen.

Upvotes: 2

Views: 1888

Answers (1)

Xcoder
Xcoder

Reputation: 1807

You probably set the wrong content size for the scrollview and hence it is scrolling horizontally.

scrollView.contentSize = CGSizeMake(scrollView.frame.size.width, sizeOfContent);

Upvotes: 2

Related Questions