// 话题网页内容
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...