Swift3 KWWebView的页面屏幕自适应
2024-08-27 11:38:09
lazy var webView: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;
_myWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0,CGRectGetMaxY(headerView.frame)+10, M_S.width,M_S.height - CGRectGetMaxY(headerView.frame) - 40) configuration:wkWebConfig];
*/
let js = "var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width'); document.getElementsByTagName('head')[0].appendChild(meta)";
let configuration = WKWebViewConfiguration()
let userScript = WKUserScript(source: js, injectionTime: .atDocumentEnd, forMainFrameOnly: true)
let wkUController = WKUserContentController()
wkUController.addUserScript(userScript)
configuration.userContentController = wkUController;
let wkView = WKWebView(frame: CGRect(x: 0.0, y: 64.0, width: swidth, height: sheight-64), configuration: configuration)
wkView.navigationDelegate = self
wkView.scrollView.delegate = self;
return wkView;
}()
参考:http://stackoverflow.com/questions/26295277/wkwebview-equivalent-for-uiwebviews-scalespagetofit
最新文章
- CSS3——transform学习
- javaccript学习1
- 自定义getElementByClass
- best matched pair
- CLR的执行模型
- JavaWeb学习记录(七)——MVC操作数据库增删改查与分页功能
- [置顶] Hibernate的一个经典异常
- d029: 求出2-100之间的所有质数(素数)
- 添加jar
- c# 用正则表达式在指定的字符串中每隔指定个数的文字插入指定字符串
- django中使用Model的update_or_create函数时报错
- Docker 集群
- MQ &; RPC 消息队列与RPC的区别与使用场景
- python3中list列表的一些操作
- python的几个小程序
- Simultaneous Localization and Mapping Technology Based on Project Tango
- 使用chrome控制台作为日志查看器
- uva10003
- POJ 2462 / HDU 1154 Cutting a Polygon
- Redis学习---Redis操作之Python连接
热门文章
- Java中关键字static的使用
- lodash 中常用的方法
- python 日志滚动 分文件
- log4j日志整合输出(slf4j+commonslog+log4j+jdklogger)
- oracl之导入dmp文件
- 别人的Linux私房菜(2)Linux简介
- 51.从首页内容跳转到第二个Tabbar控制器(controller)
- ios 数组和字典
- 2019.01.16 bzoj4399: 魔法少女LJJ(线段树合并)
- 2018.11.02 NOIP模拟 优美的序列(数论+单调栈/链表)