用户登录
用户注册

分享至

把 H5 添加到 xcode 项目方法

  • 作者: 情到深处洞自开_情仔
  • 来源: 51数据库
  • 2021-08-30

最近遇到一个问题:如何把H5添加到xcode项目中?而不是通过URL的形式来引用它。经过多方查证最终找到一个方法,现在把它分享出来,希望对大家有所帮助!

1、在xcode中新建一个文件夹,来存放你的H5页面、image等。选择Create groups。
2、添加的 .html、image文件时选择 Create folder references。
3、最后添加如下代码,引用你需要的.html页面。
//创建要打开的html文件的完整路径 NSBundle *bundle = [NSBundle mainBundle]; NSString *resPath = [bundle resourcePath]; NSString *filePath = [resPath stringByAppendingPathComponent:@"jieting.html"]; //初始化一个UIWebView实例 _webView = [[WKWebView alloc] initWithFrame:self.view.frame]; //加载指定的html文件 [_webView loadRequest:[[NSURLRequest alloc] initWithURL:[[NSURL alloc] initFileURLWithPath:filePath]]]; [self.view addSubview:_webView];

谢谢

软件
前端设计
程序设计
Java相关