iOS项目中使用项目中的html js css 文件时,有时会遇到引用路径出错的问题,致使html js css image文件没法加载的状况。css
那么,引入H5相关文件的正确操做方式以下,这样就不会出现资源文件没法引入并正常使用的状况:html
1 在项目目录下建立存放Html5文件文件夹:H5spa
2 将文件夹H5拖放至项目中对应的位置,此处注意要选择:Create groups.net
3 将各类Html5文件(html js css image等)拖放到H5文件夹中,此处注意选择:Create folder referencescode
PS:黄色为groups , 蓝色为folderhtm
4 UIWebView/WKWebView中的代码以下:blog
1 //建立要打开的html文件的完整路径 2 NSBundle *bundle = [NSBundle mainBundle]; 3 NSString *resPath = [bundle resourcePath]; 4 NSString *filePath = [resPath stringByAppendingPathComponent:@"index.html"]; 5 //初始化一个UIWebView实例 6 myWebView = [[UIWebView alloc] initWithFrame:self.view.frame]; 7 //加载指定的html文件 8 [myWebView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initFileURLWithPath:filePath]]]; 9 [self.view addSubview:myWebView];
此时已经成功添加了Html5文件到项目中,并在UIWebView中展现出来了。资源
相关内容能够参考:http://blog.csdn.net/fanjunxi1990/article/details/9352917string