WKWebView内容自适应宽度

移动开发 waitig 1208℃ 百度已收录 0评论
  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];

本文由【waitig】发表在等英博客
本文固定链接:WKWebView内容自适应宽度
欢迎关注本站官方公众号,每日都有干货分享!
等英博客官方公众号
点赞 (0)分享 (0)