我可以像这样在 UIWebView 中加载外部 URL:
let url = NSURL(string: "http://www.google.com")
let request = NSURLRequest(URL: url)
webView.loadRequest(request)
但是如何加载本地 html 文件呢?
这个solution中的答案看起来很有希望,但 Xcode 说 NSString.stringWithContentsOfFile() 已被弃用。
最佳答案
您基本上可以做您现在正在做的事情,只需使用 NSBundle
获取本地文件的 URL,如下所示:
if let url = NSBundle.mainBundle().URLForResource("index", withExtension: "html") {
webView.loadRequest(NSURLRequest(URL: url))
}
关于ios - 如何加载本地html到UIWebView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25839680/