您的位置:首页 > 移动开发

转载:UIWebView用法

2011-11-24 21:22 369 查看
转载自 http://www.devdiv.com/home.php?mod=space&uid=11826&do=blog&id=6081


转载:UIWebView用法

已有 201 次阅读 2011-10-28 17:31 |个人分类:iosUIWebView


载入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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  safari html encoding ios