如何在我的 iphone xcode 项目中添加 html 页面?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5201997/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how do i add html page in my iphone xcode project?
提问by user601367
can anyone tell how to add html in my iphone project?? And their is no html option which i click on add new file in class group...why is that???
谁能告诉我如何在我的 iphone 项目中添加 html?他们没有 html 选项,我点击在班级组中添加新文件......为什么?
回答by Xiao Xiao
simply create a blank file and rename it to html or add existing html file to the project. the next step depends on how you wish to use the html file.
只需创建一个空白文件并将其重命名为 html 或将现有的 html 文件添加到项目中。下一步取决于您希望如何使用 html 文件。
Say if you want to load a local file called page.html, first you add the file to project,and in the build phases of your project, and the page.html to Copy Bundle Resources
, and run this in your app, it writes the file to the documents
dictionary of your app/
假设你想加载一个名为 page.html 的本地文件,首先你将该文件添加到项目中,然后在项目的构建阶段,将 page.html 添加到Copy Bundle Resources
,然后在你的应用程序中运行它,它会将文件写入在documents
您的应用程序的字典/
NSString *Html = [[NSString alloc]initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"page" ofType:@"html"] encoding:NSUTF8StringEncoding error:NULL];
[Html writeToFile:[[self docPath]stringByAppendingPathComponent:@"page.html"] atomically:YES encoding:NSUTF8StringEncoding error:NULL];
[Html release];
and your webview should call this to load the file:
并且您的 webview 应该调用它来加载文件:
NSArray *docPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docPath = [docPaths objectAtIndex:0];
[myWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[docPath stringByAppendingPathComponent:@"page.html"]]]];
and it's done.
它完成了。
回答by hotpaw2
What you might be looking for is documentation and example code for the UIWebView class of UIKit.
您可能正在寻找的是 UIKit 的 UIWebView 类的文档和示例代码。
回答by Robin
You can use UIWebView
to show your html file like this
您可以使用UIWebView
这样显示您的 html 文件
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:URLString]];
[webView loadRequest:request];
where URLString
contains is your file url.
其中URLString
contains 是您的文件 url。