Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwanted white space on left of UIScrollView on iPhone X

UIScrollView works fine without the white space on the left on all iPads or iPhones except for iPhone X. How can I remove the white space?

I use storyboards. Bounce On Scroll/Zoom are all disabled. No white space on iPad or iPhone except for iPhone X. I think it might be something related to the Safe Area thing.

enter image description here

like image 719
zs2020 Avatar asked Oct 22 '17 23:10

zs2020


1 Answers

This spacing is from safe area, which is applied to left/right of UIScrollview as content insets in landscape orientation on iPhone X, which can be seen using read-only property UIScrollview.safeAreaInsets.

Following line can be used to get rid of safe area insets when you dont need:

UIScrollview.contentInsetAdjustmentBehavior = .never

The default value being UIScrollViewContentInsetAdjustmentBehavior.automatic includes safe area layout guide margins as content insets.

Note: auto layout constraints has nothing to do with the insets, its just iOS 11 UIScrollview content insets adjustment behavior.

like image 55
AamirR Avatar answered Oct 05 '22 03:10

AamirR