zoukankan      html  css  js  c++  java
  • iOS项目中如何正确引入Html5文件(html/js/css)

    iOS项目中使用项目中的html js css 文件时,有时会遇到引用路径出错的问题,导致html js css image文件无法加载的情况。

    那么,引入H5相关文件的正确操作方式如下,这样就不会出现资源文件无法引入并正常使用的情况:

    1 在项目目录下创建存放Html5文件文件夹:H5

    2 将文件夹H5拖放至项目中对应的位置,此处注意要选择:Create groups

    3 将各种Html5文件(html js css image等)拖放到H5文件夹中,此处注意选择:Create folder references

    PS:黄色为groups , 蓝色为folder

    4 UIWebView/WKWebView中的代码如下:

    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/9352917

  • 相关阅读:
    C#生成唯一值的方法汇总
    Ajax && json在springmvc中的使用
    spring集成mybatis
    mybatis iBatis
    springjdbc
    拦截器
    系统分层
    Java反射(reflect)
    springmvc
    spring 之 使用注解简化配置
  • 原文地址:https://www.cnblogs.com/jaysonguo/p/6019023.html
Copyright © 2011-2022 走看看