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

IOS UIwebView加载本地文件(支持图片)

2014-07-11 10:51 204 查看
1,本地的html文件一定要放到工程文件的根目录

2,html代码中的图片路径一定要是相对路径

3,下面是用UIWebView调用本地文件的方法

方法一:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding
error:nil]

[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];

方法二:

NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

NSURL *url = [NSURL fileURLWithPath:filePath];

NSURLRequest *request = [NSURLRequest requestWithURL:url];

[myWebView loadRequest:request];

[self.view addSubview:myWebView];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: