首页 > 代码库 > UIWebView的三种加载方式

UIWebView的三种加载方式

1、直接给出url地址即可将web content载入。
NSString *path = @"http://theo2life.com";  
NSURL *url = [[NSURL alloc] initWithString:path];  
[self.webView loadRequest:[NSURLRequest requestWithURL:url]]; 

2、将本地html文件内容嵌入webView
NSString *resourcePath = [ [NSBundle mainBundle] resourcePath];  
NSString *filePath  = [resourcePath stringByAppendingPathComponent:@"test.html"];  
NSString *htmlstring =[[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];   
[self.webView loadHTMLString:htmlstring  baseURL:[NSURL fileURLWithPath: [[NSBundle mainBundle]  bundlePath]]];  


3.如果不从html文件载,直接加载NSString:
NSString *HTMLData = http://www.mamicode.com/@"hello web";  >

UIWebView的三种加载方式