美文网首页
解决WKWebView加载的元素过小的问题

解决WKWebView加载的元素过小的问题

作者: 春暖花已开 | 来源:发表于2017-12-19 14:27 被阅读25次
    - (WKWebView *)webView {
        if (!_webView) {
            _webView = [[WKWebView alloc] init];
            //以下代码适配大小
            NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta);";
            
            WKUserScript *wkUScript = [[WKUserScript alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
            WKUserContentController *wkUController = [[WKUserContentController alloc] init];
            [wkUController addUserScript:wkUScript];
            
            WKWebViewConfiguration *wkWebConfig = [[WKWebViewConfiguration alloc] init];
            wkWebConfig.userContentController = wkUController;
            
            _webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:wkWebConfig];
            [self.view addSubview:_webView];
            _webView.navigationDelegate = self;
        }
        return _webView;
    }
    

    相关文章

      网友评论

          本文标题:解决WKWebView加载的元素过小的问题

          本文链接:https://www.haomeiwen.com/subject/qxgbwxtx.html