How to get rid of the status bar background on the UIWebView?

大城市里の小女人 提交于 2019-12-02 12:26:22

This happens because of UIScrollView new behavior to adjust the content inset to include safe area insets like the status bar.

To fix it, just set it to UIScrollViewContentInsetAdjustmentNever

[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];

Since iOS 11 Beta 4 you can add this to your viewport and will also remove the fake statusbar

viewport-fit=cover

dpogue

To do this entirely in HTML/CSS, viewport-fit=cover in the Viewport meta tag is the correct way to handle this.

But you'll also want to adjust your padding dynamically to handle the differently sized status bar on iPhone X with its notched camera/speaker.

Luckily, Apple exposed some CSS constants for the safe area insets, so you can take advantage of those in your CSS: i.e., padding-top: constant(safe-area-inset-top);

I wrote a bit more about this scenario and the new features for iOS 11 and iPhone X: https://ayogo.com/blog/ios11-viewport/

Swift version:

webView.scrollView.contentInsetAdjustmentBehavior = .never
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!