首页 > 移动平台 > 详细

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

时间:2014-11-26 13:53:01      阅读:331      评论:0      收藏:0      [点我收藏+]

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];

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

原文:http://www.cnblogs.com/BinZone/p/4122904.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!