I am updating my iOS app to replace UIWebView
with WKWebView
. However I don't understand how to achieve the same behavior with WKWebView
. With UIWebView
I used scalesPageToFit
to ensure the web pag was displayed with the same size as the screen size (so as to appear full screen without scrolling).
I found that solution on the web however it does not work :
- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
NSString *javascript = @"var meta = document.createElement('meta');meta.setAttribute('name', 'viewport');meta.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no');document.getElementsByTagName('head')[0].appendChild(meta);";
[webView evaluateJavaScript:javascript completionHandler:nil];
}