ios - WKWebView equivalent for UIWebView's scalesPageToFit -


I change your iOS app to change UIWebView to WKWebView I'm updating. Although I do not understand how to get the same behavior with WKWebView . I used scalesPageToFit with UIWebView to ensure the web pag was displayed with the same size as the screen size (so that full screen is displayed without scrolling ).

I found this solution on the Web but it does not work:

  - (zero) webview: (wk webview *) webview was communicated: (wk navigation * Navigation {nssting * javascript = @ "met meta = document.createElement ('meta'); meta.setAttribute ('name', 'viewport'); meta.setAttribute ('content', 'width = device-width, Initial-scale = 1.0, max-scale = 1.0, user scalable = no '); document. GetElementsByTagName (' head ') [0] .appendChild (meta); "; [Evaluate webview javascript: javascript closing handler: zero]; }    

You can also try WKUserScript.

Here's my working configuration:

  NSString * jScript = @ "var meta = document.createElement ('meta'); meta.setAttribute ('name' , 'Viewport'); meta.setAttribute ('content', 'widthth = device-width'); document.getElementsByTagName ('head') [0] .appendChild (meta); "; WKUserScript * wkUScript = [[WKUserScript alloc] initWithSource: JScript Injection Time: WKUserScriptInjectionTimeAtDocumentEndforMainFrameOnly: Yes]; WKUserContentController * wkUController = [[WKUserContentController alloc] init]; [WkUController addUserScript: wkUScript]; WKWebViewConfiguration * wkWebConfig = [[WKWebViewConfiguration alloc] init]; WkWebConfig.userContentController = wkUController; WkWebV = [[WKWebView alloc] initWithFrame: self.view.frame configuration: wkWebConfig];   

You can add additional configurations to your WKWebViewConfiguration.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -