当前位置: 移动技术网 > 移动技术>移动开发>IOS > 把 H5 添加到 xcode 项目方法

把 H5 添加到 xcode 项目方法

2020年07月23日  | 移动技术网移动技术  | 我要评论

最近遇到一个问题:如何把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];

谢谢

本文地址:https://blog.csdn.net/qq_45039822/article/details/107518101

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网