zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    郁闷的Alexa破10万。
    回到杭州,2009开始了。
    美剧。
    英来网招聘:兼职js开发。(补充)
    村姑的Beta 2.0,TT。
    爆牙齿的Web标准面试考题II(iPhone SMS/iChat UI的Web标准实现)
    天使飞来。
    Web标准的未来,浏览器的未来,应用的未来。
    咖啡厅与产品形态。
    学习使用笔和纸。
  • 原文地址:https://www.cnblogs.com/mapanguan/p/6405619.html
Copyright © 2011-2022 走看看