转载自 http://www.devdiv.com/home.php?mod=space&uid=11826&do=blog&id=6081
转载:UIWebView用法
||
载入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
1.NSString *webpage = [ NSBundle pathForResource : @ "webpage" ofType : @ "html" inDirectory : [ [ NSBundle mainBundle ]bundlePath ] ];2.[uiwebview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:webpage]]];
载入HTML 3
1.[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;
}
}