Search code examples
iosuiscrollviewbackground-coloriphone-xsafearealayoutguide

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


Solution

  • Well, I solved this issue in non-elegant way. But it works like a charm. (I tried all other answers. Thank for your help, however those answers don't seem to work in my case.)

    var leftMargin: CGFloat = 0
    var rightMargin: CGFloat = 0
    
    if Device.isPhone() && Device.IS_5_8_INCHES() {
        self.leftMargin = 44
        self.rightMargin = 44
    }
    
    let frame = CGRect(
        x: (self.view.frame.width - self.leftMargin - self.rightMargin) * CGFloat(pageIndex),
        y: ...
    )