Removing scrollbars in iOS for WKWebViewEngine

Viewed 129

I have a Cordova app that is since recently using WKWebViewEngine and I noticed horizontal and vertical scrollbars appearing since switching.

I researched and the issue is documented at: https://issues.apache.org/jira/browse/CB-10123

A CSS fix does not work but there is apparently a fix with using:

self.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
self.wkWebView.scrollView.showsHorizontalScrollIndicator = NO;

The question is where do I add this fix? I checked in CDVWKWebViewEngine.m but am not sure where to add it.

1 Answers

In case it helps, in a pure iOS app those 2 lines of code :

self.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
self.wkWebView.scrollView.showsHorizontalScrollIndicator = NO;

would typically be placed within the view controller viewDidLoad function.

I don't know the details of Cordova, but you should find your view's view controller (could be CDVViewcontroller in CDVViewcontroller.m (?)) and add those lines at the end of the viewDidLoad method.

Alternatively (and certainly cleaner), you could subclass CDVViewcontroller into your own ViewController class and override viewDidLoad like this

- (void)viewDidLoad {
    [super viewDidLoad];
    self.wkWebView.scrollView.showsVerticalScrollIndicator = NO;
    self.wkWebView.scrollView.showsHorizontalScrollIndicator = NO
}

then find a way to force Cordova to use your view controller class instead of its own.

Take care, in the codes I've read, the web view property is called webView and not wkWebView, so you might need to change that in your two lines.

Related