I created a UIScrollView in my storyboards and have added 12 UIButtons in a container View which is inside the UIScrollView.
when running on the iPhone 5s simulator,
Add all subviews from container to ScrollView. And hide the container. Make sure container(ContainerView of scrollView) should also be a subView of scrollView.
It seems you need to increase the frame height of container view. The contentSize
of scrollView only affects how it will scroll, which is irrelevant here.
If the button is outside the container view, it will still show up. However, it can't respond to any touch event.
Just increase the container view height and also Container view must be a subview of the scroll view and all other subviews are part of the container view.
like Scroolview -> ContainerView--> UIButtons
when using scrollview in storyboard with autolayout. it is usually set up using a content view inside the scrollview that will contain all the other views (e.g. buttons, labels, etc.) the content view are usually set to have equal height and equal width.
to make your content view expand it's height, you need to add a height constraint then assign it to an outlet so you could easily manipulate it's value with in your code. then set the content view's height constraint priority to 1000 ("required") and set the content view's "equal width to:view" constraint priority to 750 (high).
Another option is to reduce the priority on the Content View.Center Y constraint.
In Xcode 9, I laid out the contentView as needed and the button extended below the view on the iPhone 5. I dynamically resized the scrollView.contentSize.height and contentView.frame in the view controller. The scrollView scrolled for me but I was still unable to select the button and was seeing warnings in the Storyboard.
Once I lowered the priority on the Center Y Alignment Constraint for the contentView, the warnings in Storyboard disappeared and I was able to scroll to the bottom of the scrollView and select the button on the iPhone 5 simulator.
NOTE: I'm still checking the device size and resizing the scrollView.contentSize.height value in viewWillLayoutSubviews() for small devices.
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
scrollView.contentSize.height = (UIDevice.current.isSmallDevice) ? 560 : contentView.frame.size.height
}
(UIDevice.current.isSmallDevice is a call to an extension of UIDevice that returns a bool determined by screen size)
For me it was all just to Uncheck the checkbox Adjust Scroll View Insets in the storyboard of that ViewController.
PS: The above answers didn't worked for me.