【问题标题】:how to embed html file into xcode in the webview?如何将 html 文件嵌入到 webview 中的 xcode 中?
【发布时间】:2015-01-22 10:14:15
【问题描述】:
嘿,伙计们,我最近一直在使用 html 和 javascript 开发移动应用程序,进展顺利,但现在我想将 html 文件嵌入到 xcode 项目中,这样我就可以在我的 iphone 上运行它而无需使用 phonegape 但是没有运气......
i tried viewing some video tutorial reading some articles but not one worked with me ...
所以谁能告诉我(详细一步一步)如何做到这一点。
附言我是 xcode 的新手,我只用了几天。
【问题讨论】:
标签:
html
xcode
webview
cross-platform
【解决方案1】:
您可以使用 xcode 在 uiwebview 中打开本地 html 文件,这是一个将该文件转换为字符串然后将其加载到 uiwebview 中的示例
NSString *htmlStr = [[NSBundle mainBundle] pathForResource:@"yourfilename" ofType:@"html"];
NSString* htmlString = [NSString stringWithContentsOfFile:htmlStr encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];
希望对你有帮助