In this post we will see, how to fix scrolling issues for UIScrollView with autolayout. Follow below steps to learn how can we fix scrolling issue with UIScrollView while using auto layout, to design our user interface in storyboard that contains UIScrollView with autolayout.
Step 1: Drag UIScrollView to the view, add constraints to the scroll i.e. leading, trailing, top, bottom with respect to superview.
Step 2: Drag UIView to your scroll view as this will act as your content view. Set constraints to the view i.e. leading, trailing, top, bottom with respect to superview.Add horizontally in container constraint to the container view.
Step 3: Add height constraint to your view that was added by us in step 2.
Step 4: Create IBOutlet to our height constraint using NSLayoutConstraint.
in.h file
IBOutlet NSLayoutConstraint *contentHeight;
Add height constraint to our UIView added to UIScrollview |
Step 5: Now change contentHeight value in your viewDidLoad
}
Step 6: Run your app, you will see that now you can scroll your UIScrollView while using auto layout.
Output for UIScrollView while using auto layout |