Cod*_*ray 64
以下代码将加载index.html项目文件夹中指定的HTML文件:
[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];
Run Code Online (Sandbox Code Playgroud)
dea*_*rne 28
科迪格雷是对的,但也有这样的方式:
// Load the html as a string from the file system
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *html = [[NSString alloc] initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
// Tell the web view to load it
[WebView loadHTMLString:html baseURL:[[NSBundle mainBundle] bundleURL]];
Run Code Online (Sandbox Code Playgroud)
如果您需要在加载之前编辑html,这非常有用.
迅速
guard let path = NSBundle.mainBundle().pathForResource("index", ofType: "html") else {
return
}
let url = NSURL(fileURLWithPath: path)
self.webview.loadRequest(NSURLRequest(URL:url))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37309 次 |
| 最近记录: |