BoR
BoR

Reputation: 83

How add Vertical Scroll for ViewController

How to add the Vertical scrolling for View Controller.

I have tried the below steps. But I cannot achieve the scrolling.

changed the simulated size of the view controller from fixed to the free form

set the width and height of the view controller

Add scroll view . Moved the UI elements to Scroll View

Added the following code in UIViewController class in viewDidLoad()

scrollView.contentSize = CGSize(width: self.view.frame.width, height: 800)

Please provide me input on this

Upvotes: 2

Views: 2693

Answers (1)

Notsileous
Notsileous

Reputation: 560

ScrollViews in iOS are the most maddening things I have ever seen in my life.
Are you using Auto-Layout? One thing to look at is the constraints, Xcode loves to add constraints that break everything. Look through the constraints and see if any are weird looking, especially ones that are constant +/- a large number.

Try putting all your UI elements into a view, and put the view in the scroll view. If it still wont work, try to then make this view larger than the scroll view and limit the scroll view to the phone screen size.

Finally try to find a working scrollview example and compare the components and constraints and see if it will help with yours. This worked for me when I was first starting to deal with them.

Upvotes: 1

Related Questions