从Nib或Storyboard在WKWebView上设置WKWebViewConfiguration [英] Set WKWebViewConfiguration on WKWebView from Nib or Storyboard

查看:576
本文介绍了从Nib或Storyboard在WKWebView上设置WKWebViewConfiguration的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple在iOS 11中添加了功能集,可在笔尖和情节提要板上添加WKWebViews插座.使用自动设置的默认WKWebViewConfiguration时,它似乎可以正常工作.

With iOS 11 Apple has added the ability set add WKWebViews outlets on your nibs and storyboards. It seems to work fine when using the default WKWebViewConfiguration that get set automatically.

但是,我希望能够使用自定义的WKWebViewConfiguration.无论如何,我可以在笔尖初始化WKWebView之前或之后进行设置吗?

However, I'd like to be able to use a custom WKWebViewConfiguration. Is there anyway I can set this before, or after the WKWebView gets initialized from the nib?

推荐答案

让我们以您的自定义配置示例为例.

Let's Example your customize configuration.

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];

//Here you can customize configuration
[self.webView.configuration.userContentController addUserScript:wkUScript];

// self.webView.navigationDelegate = self;
// self.webView.contentMode = UIViewContentModeScaleAspectFill;

这篇关于从Nib或Storyboard在WKWebView上设置WKWebViewConfiguration的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆