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;
    
    // 创建一个view来控制scrollview的contentsize
    self.wk = [[WKWebView alloc] initWithFrame:CGRectMake(10, 0, Main_Screen_Width - 20, 200) configuration:wkWebConfig];

你可能感兴趣的:(WKWebView内容自适应宽度)