1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > webview 本地 html空白 WKWebView加载本地html遇到的坑与解决办法

webview 本地 html空白 WKWebView加载本地html遇到的坑与解决办法

时间:2019-06-17 19:39:05

相关推荐

webview 本地 html空白 WKWebView加载本地html遇到的坑与解决办法

1、字体变小解决办法

Swift

let headerString = ""

self.wkwebview.loadHTMLString(headerString.appending(html), baseURL: nil)

Objective-C

NSString *headerString = @"";

[strongSelf.contentWebView loadHTMLString:[headerString stringByAppendingString:model.detail] baseURL:nil];

2、空格太大的解决办法

遇到iOS的空格比安卓大很多

// 去掉所有空格

html = htmlStr.replacingOccurrences(of: "", with: "").replacingOccurrences(of: "

", with: "")

当html中有表格且格子里是空的,与要加上空格

//给空表格中间加空格

html = html.replacingOccurrences(of: "

", with: "")

3、调整图片显示边距,视频边距,行间距,表格边距

//css

let htmlString = String(format:"%@",html)

4、设置html中视频播放时不进入全屏

//先设置WKWebViewConfiguration

let configuration = WKWebViewConfiguration()

configuration.allowsInlineMediaPlayback = true

wkwebview = WKWebView(frame: .zero, configuration: configuration)

//调用js设置

//防止有多个视频

guard self.totalHtml.contains("

return

}

let arr = ponents(separatedBy: "

for i in 0 ..< arr.count {

//设置视频在webview 上播放

let webkitPlaysinline = "document.getElementsByTagName('video')[\(i)].setAttribute('webkit-playsinline', true)"

webView.evaluateJavaScript(webkitPlaysinline, completionHandler: { (data, error) in

printLog(message: data)

})

let x5Playsinline = "document.getElementsByTagName('video')[\(i)].setAttribute('x5-playsinline', true)"

webView.evaluateJavaScript(x5Playsinline, completionHandler: { (data, error) in

printLog(message: data)

})

let playsinline = "document.getElementsByTagName('video')[\(i)].setAttribute('playsinline', true)"

webView.evaluateJavaScript(playsinline, completionHandler: { (data, error) in

printLog(message: data)

})

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。