• Swift3 KWWebView的页面屏幕自适应


      lazy var webView:WKWebView = {
            /*
             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;
             _myWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(headerView.frame)+10, M_S.width,M_S.height - CGRectGetMaxY(headerView.frame) - 40) configuration:wkWebConfig];
             */
            let js = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta)";
            let configuration = WKWebViewConfiguration()
            let userScript = WKUserScript(source: js, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
            let wkUController = WKUserContentController()
            wkUController.addUserScript(userScript)
            configuration.userContentController = wkUController;
            let wkView = WKWebView(frame: CGRect(x: 0.0, y: 64.0,  swidth, height: sheight-64), configuration: configuration)
            wkView.navigationDelegate = self
            wkView.scrollView.delegate = self;
            return wkView;
        }()
    

      参考:http://stackoverflow.com/questions/26295277/wkwebview-equivalent-for-uiwebviews-scalespagetofit

  • 相关阅读:
    -_-#【MongoDB】日期类型
    -_-#【Better Code】字符串匹配
    -_-#【Canvas】圆弧运动
    -_-#【Canvas】
    -_-#【AngularJS】
    COGS——C 14. [网络流24题] 搭配飞行员
    CODEVS——T 1993 草地排水 USACO
    BZOJ——T2190: [SDOI2008]仪仗队
    Codeforces_GYM_100741 A
    2017-0722 模拟赛
  • 原文地址:https://www.cnblogs.com/mapanguan/p/6405619.html
Copyright © 2020-2023  润新知