• 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

  • 相关阅读:
    JS实现类似网页的测试考卷
    Following Orders(poj1270)
    1007
    Intervals(poj1201)
    LightOJ
    1002
    King's Order(hdu5642)
    Beautiful Walls
    A. Watchmen(Codeforces 650A)
    Shortest Path(hdu5636)
  • 原文地址:https://www.cnblogs.com/mapanguan/p/6405619.html
Copyright © 2020-2023  润新知