self.webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 66, W, self.view.frame.size.height-66)];
NSString *mainBundleDirectory=[[NSBundle mainBundle] bundlePath];
NSString *path=[mainBundleDirectory stringByAppendingPathComponent:@"anjie.html"];
NSURL *url=[NSURL fileURLWithPath:path];
NSURLRequest *request=[[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:30];
self.webView.scalesPageToFit=YES;
[self.webView loadRequest:request];
self.webView.delegate = self;
[self.view addSubview:self.webView];
本文介绍如何在iOS应用中使用UIWebView加载本地HTML文件。通过设置WebView的frame并利用NSBundle获取本地HTML路径,创建NSURLRequest加载请求,最终将HTML内容显示在WebView中。
633

被折叠的 条评论
为什么被折叠?



