ios--UIwebView加载本地文件(支持显示图片)
2014-02-25 09:16
453 查看
1,本地的html文件一定要放到工程文件的根目录
2,html代码中的图片路径一定要是相对路径
3,下面是用UIWebView调用本地文件的方法
方法一:
- (void)viewDidLoad
{
[super viewDidLoad];
webView.backgroundColor = [UIColorclearColor];
webView.scalesPageToFit =YES;
webView.delegate =self;
NSString *basePath = [[NSBundlemainBundle]bundlePath];
NSString *helpHtmlPath = [basePath stringByAppendingPathComponent:@"jsIOS.html"];
NSURL *url = [NSURLfileURLWithPath:helpHtmlPath];
[webViewloadRequest:[NSURLRequestrequestWithURL:url]];
}
方法二:
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];
方法三:
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:filePathencoding:NSUTF8StringEncoding
error:nil]
[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
2,html代码中的图片路径一定要是相对路径
3,下面是用UIWebView调用本地文件的方法
方法一:
- (void)viewDidLoad
{
[super viewDidLoad];
webView.backgroundColor = [UIColorclearColor];
webView.scalesPageToFit =YES;
webView.delegate =self;
NSString *basePath = [[NSBundlemainBundle]bundlePath];
NSString *helpHtmlPath = [basePath stringByAppendingPathComponent:@"jsIOS.html"];
NSURL *url = [NSURLfileURLWithPath:helpHtmlPath];
[webViewloadRequest:[NSURLRequestrequestWithURL:url]];
}
方法二:
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];
方法三:
NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];
NSString *htmlString = [NSString stringWithContentsOfFile:filePathencoding:NSUTF8StringEncoding
error:nil]
[myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];
相关文章推荐
- IOS UIwebView加载本地文件(支持图片)
- ios 加载本地HTML文件,图片不显示的问题
- iOS 加载本地HTML文件,图片没显示出来的问题
- IOS UIwebView加载本地文件(支持显示图片)
- monotouch在使用uiwebview时加载本地html文件时的图片显示
- iOS UIWebView加载本地图片
- iOS之支持https与ssl双向验证(包含:解决UIWebView加载不了https网页的图片,css,js等外部资源)
- ios的webView加载本地html图片路径显示及webview适配
- iOS开发:通过UIWebView加载读取本地文件(word文档)
- UIWebView 本地加载网页和文件(图片素材,js,css)(功能插件化)
- iOS之支持https与ssl双向验证(包含:解决UIWebView加载不了https网页的图片,css,js等外部资源)
- 【iOS开发】UIWebView加载html时不显示网络图片解决办法
- 【IOS 开发】UIWebView 加载本地文件,多层的网页目录结构失败分析和解决,以及demo
- UIWebView加载本地HTML文件中有本地图片的索引
- ios-day20-02(使用UIWebView加载Bundle或者沙盒中的本地文件(PDF、txt、doc))
- UIWebView加载本地html控制横向滚动条消失,并且显示html中的本地图片
- iOS开发UIWebView如何加载本地带有JS和本地图片的网页
- iOS WebView 加载本地资源(图片,文件等)
- 前端本地客户端压缩图片,兼容IOS,Android,PC、自动按需加载文件
- UIWebView中显示加载本地的图片