添加文件
1. 選擇Create groups
此時(shí)HTML等資源文件不存在目錄結(jié)構(gòu),對(duì)
.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
此時(shí)HTML等資源文件存在目錄結(jié)構(gòu)嫡纠,對(duì)
.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];