Swift - contents within scrollview get chop off

Viewed 51

Facing an issue when scrolling, a part of content didn't displayed.

https://i.stack.imgur.com/70FIC.png

Here it is what is supposed to be displayed

https://i.stack.imgur.com/ViPjF.png

My UI is designed in storyboard, the structure for the scrollable component is as below:

UIView -> UIScrollView -> UIStackView -> Multiple UIViews

If wondering how I take the screenshot of the one that's supposed to be displayed, the price is a drawer component, somehow after I tapped the drawer component, the content will be displayed, but after I scroll to top, same issue will happen to the content, which they get chop off.

https://i.stack.imgur.com/OKSEY.png

Updates:

Trying to put background colour on views to see which view is blocking the scrollview.

https://i.stack.imgur.com/vZBY7.png

Found that the scrollview (Booking DetailsSV) blocked by its superview (Booking Details View) in the hierarchy. Here is the screenshot taken in the test phone.

https://i.stack.imgur.com/Wm7xa.png

Is it suppose to happen like this?

1 Answers

Your scrollview doesn't seem to have correct contentSize. You need to set content size of your scrollView like following:

let sizeOfContent = 500

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

You can do this in viewDidLoad.

Related