• WKWebView加载Html文件,如何自适应网页内容呢?就是不要让它左右滑动


    WKWebView* webView = _realWebView;
            
            NSString *jScript = @"var meta = document.createElement('meta');
            meta.name = 'viewport';
            meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no';
            var head = document.getElementsByTagName('head')[0];
            head.appendChild(meta);";
            
            if(scalesPageToFit)
            {
                WKUserScript *wkUScript = [[NSClassFromString(@"WKUserScript") alloc] initWithSource:jScript injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:NO];
                [webView.configuration.userContentController addUserScript:wkUScript];
            }
            else
            {
                NSMutableArray* array = [NSMutableArray arrayWithArray:webView.configuration.userContentController.userScripts];
                for (WKUserScript *wkUScript in array)
                {
                    if([wkUScript.source isEqual:jScript])
                    {
                        [array removeObject:wkUScript];
                        break;
                    }
                }
                for (WKUserScript *wkUScript in array)
                {
                    [webView.configuration.userContentController addUserScript:wkUScript];
                }
            }

    webview.scalespagetofit只有UIWebView才有

  • 相关阅读:
    Socket通信的理解
    wpf listbox 内的内容显示问题,需要设置里面的itemsPresenter
    C#的两个大方向
    QT的安装和配置及helloqt程序的编写时遇到的问题
    华为交换机基础命令
    华为创建VLAN及VLAN间通讯
    powershell查询AD域账号详细信息
    Powershell从EXCEL导入大量用户
    映射网络驱动器
    域策略更新及导出
  • 原文地址:https://www.cnblogs.com/xieyunqq/p/5711508.html
Copyright © 2020-2023  润新知