// 话题网页内容
CGFloat contentW = XJ_ScreenWidth - 20 ;
CGFloat contentX = 10;
NSString *jScript = @"var meta = document.createElement('meta'); meta.setAttribute('name', 'viewport'); meta.setAttribute('content', 'width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no'); 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;
self.contentWbv = [[WKWebView alloc] initWithFrame:CGRectMake(contentX, HEIGHT(titleLb) + Y(titleLb) + padding, contentW, 100) configuration:wkWebConfig];
self.contentWbv.backgroundColor = [UIColor whiteColor];
self.contentWbv.navigationDelegate = self;
self.contentWbv.scrollView.bounces = NO;
self.contentWbv.scrollView.scrollEnabled = NO;
NSString *htmls = [NSString stringWithFormat:@"<html> \n"
"<head> \n"
"<style type=\"text/css\"> \n"
"body {margin:18;font-size:14;color:0x666666}\n"
"</style> \n"
"</head> \n"
"<body>"
"<script type='text/javascript'>"
"window.onload = function(){\n"
"var $img = document.getElementsByTagName('img');\n"
"for(var p in $img){\n"
" $img[p].style.width = '100%%';\n"
"$img[p].style.height ='auto'\n"
"}\n"
"}"
"</script>%@"
"</body>"
"</html>",self.actDetailModel.brief];
[self.contentWbv loadHTMLString:htmls baseURL:nil];
iOS WKWebview loadHTMLString文字图片正常显示
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 场景:IOS模拟器里,图片可以正常加载,但是真机无法正常加载。 原因: 1.图片资源名称的大小写不能写错,例如:...
- “UIButton实现上显示图片,下显示文字”这个需求相信大家在开发中都或多或少会遇见。比如自定义分享View的时...
- 1. 粘贴板 UIPasteboard * pastboard = [UIPasteboard generalPa...