美文网首页
iOS webView 加载本地html 静态资源的路径问题

iOS webView 加载本地html 静态资源的路径问题

作者: 键盘仔 | 来源:发表于2017-07-17 08:00 被阅读144次

iOS中webView加载本地html、js、css、image的路径问题

将html、css、js、image等静态资源文件放到同一个目录www,添加到Xcode中使用as folder references方式

WX20170717-075203@2x.png

完成

278104-b68c2c01e4841544.jpeg

然后使用如下方式加载页面

NSString* filePath = [[NSBundle mainBundle] pathForResource:@"index"
                                                         ofType:@"html"
                                                    inDirectory:@"www"];
NSURL* fileURL = [NSURL fileURLWithPath:filePath];
NSURLRequest* request = [NSURLRequest requestWithURL:fileURL];
[webView loadRequest:request];

相关文章

网友评论

      本文标题:iOS webView 加载本地html 静态资源的路径问题

      本文链接:https://www.haomeiwen.com/subject/yvffkxtx.html