• WKWebview加载SVG显示不全


    WKWebview加载SVG显示不全,或者WKWebview加载html显示不全.要注入一段js代码

    - (void)configUI{

        CGFloat gap = 16;
    //    self.webview = [[WKWebView alloc] initWithFrame:CGRectMake(gap, 10,kUIScreenWidth - gap * 2 , 10)];
        // 解决内存泄露问题
        WKWebViewConfiguration*config = [[WKWebViewConfiguration alloc]init];
        config.selectionGranularity = WKSelectionGranularityCharacter;
        
        // 让网页内容自适应大小
        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];
        config.userContentController = wkUController;
        
        // 创建WKWebView
        self.webview = [[WKWebView alloc] initWithFrame:CGRectMake(gap, 10,kUIScreenWidth - gap * 2 , 10) configuration:config];
        [self.contentView addSubview:self.webview];

        self.webview.navigationDelegate = self;
    }
    - (void)configureCellWithStr:(NSString *)contentstr
    {
        //"<style>img{width:%f !important;height:auto}

        NSString *headerString = @"

    ";
        [self.webview loadHTMLString:[headerString stringByAppendingString:self.htmlStr ? self.htmlStr : @""] baseURL:nil];
    //    [self.webview loadHTMLString:self.htmlStr baseURL:nil];
     
    }

  • 相关阅读:
    Linux系统资源监控nmon工具下载及使用介绍
    QT的安装 [新版2022]
    使用dotnet-monitor分析在Kubernetes的应用程序:Sidecar模式
    荷兰国旗问题与快速排序算法
    经典伴读_GOF设计模式_行为模式(上)
    微头条项目实战:新增RequestHeader注解
    open3d安装相关问题
    libevent库event事件使用
    C#面:as 和 is 的区别
    Go语言基础面试题
  • 原文地址:https://blog.csdn.net/cola_wh/article/details/133639140