载入HTML 1
NSString *resourcePath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [resourcePath stringByAppendingPathComponent:@"webpage.html"];
NSString *htmlstring=[[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
[uiwebview loadHTMLString:htmlstring baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];
载入HTML 2
NSString *webpage = [NSBundle pathForResource:@"webpage" ofType:@"html" inDirectory:[[NSBundle mainBundle] bundlePath]];
[uiwebview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:webpage]]];
载入HTML 3
[uiwebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://zgia.net/"]]];
点击链接使用Safari打开
添加UIWebViewDelegate代理
uiwebview.delegate = self;
#pragma mark -
#pragma mark UIWebViewDelegate
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if(navigationType == UIWebViewNavigationTypeLinkClicked) {
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
}
else
{
return YES;
}
}