添加文件
addHTML.png1. 选择Create groups
此时HTML等资源文件不存在目录结构,对
.css
文件的引用需要如下格式:
href="main.css"
src="test.png"
加载代码如下:
NSString *path = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
NSString *basePath = [[NSBundle mainBundle] bundlePath];
NSURL *baseURL = [NSURL fileURLWithPath:basePath];
[self.webView loadHTMLString:htmlString baseURL:baseURL];
2. 选择Create folder references
此时HTML等资源文件存在目录结构,对
.css
文件的引用需要如下格式:
href="css/main/main.css"
src="img/test.png"
加载代码如下:
UIWebView *webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
webView.delegate = self;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"web/Stj"]]]];
[self.view addSubview:webView];
网友评论