总结-UIWebView的使用-加载网页、html文件、本地文件等
2016-09-21 21:54
579 查看
一、概念
UIWebView是用来加载html文件、网址、本地文件等的框架。
二、使用方法
0.初始化UIWebView
可以用storyboard初始化,也可以代码初始化。
if (!_webView)
{
CGRect frame = [UIScreenmainScreen].bounds;
_webView = [[UIWebViewalloc]initWithFrame:frame];
//识别webView中的类型,如有电话号码,点击直接可拨打
_webView.dataDetectorTypes =UIDataDetectorTypeAll;
_webView.delegate =self;
_webView.scalesPageToFit =YES;
[self.viewaddSubview:_webView];
}
初始化UIWebView时,_webView.dataDetectorTypes = UIDataDetectorTypeAll; 是识别webview中的类型,例如
当webview中有电话号码,点击号码就能直接打电话。
1.加载网页
NSString * urlStr = [NSStringstringWithFormat:@"http://www.baidu.com"];
NSURL
* url = [NSURLURLWithString:urlStr];
NSURLRequest * request = [NSURLRequestrequestWithURL:url];
[_webViewloadRequest:request];
2.加载本地html文件(可加载image)
//baseURL把项目根目录统一中项目下,加载double.html中的image,
css的话,不需要写路径,直接写名字就可以。这样html中的图片就可以正常显示了
NSURL * baseURL = [NSURLfileURLWithPath:[NSBundlemainBundle].bundlePath];
NSString * htmlPath = [[NSBundlemainBundle]pathForResource:@"double"ofType:@"html"];
NSString * htmlCont = [NSStringstringWithContentsOfFile:htmlPathencoding:NSUTF8StringEncodingerror:nil];
[_webViewloadHTMLString:htmlContbaseURL:baseURL];
3.加载[b]加载本地或者从服务器下载的文件,如txt,pdf,word等[/b]
//获取本地文件的url
NSURL * fileURL = [[NSBundlemainBundle]URLForResource:@"LocalFile.txt"withExtension:nil];
NSURLRequest * request = [NSURLRequestrequestWithURL:fileURL];
[_webViewloadRequest:request];
UIWebView是用来加载html文件、网址、本地文件等的框架。
二、使用方法
0.初始化UIWebView
可以用storyboard初始化,也可以代码初始化。
if (!_webView)
{
CGRect frame = [UIScreenmainScreen].bounds;
_webView = [[UIWebViewalloc]initWithFrame:frame];
//识别webView中的类型,如有电话号码,点击直接可拨打
_webView.dataDetectorTypes =UIDataDetectorTypeAll;
_webView.delegate =self;
_webView.scalesPageToFit =YES;
[self.viewaddSubview:_webView];
}
初始化UIWebView时,_webView.dataDetectorTypes = UIDataDetectorTypeAll; 是识别webview中的类型,例如
当webview中有电话号码,点击号码就能直接打电话。
1.加载网页
NSString * urlStr = [NSStringstringWithFormat:@"http://www.baidu.com"];
NSURL
* url = [NSURLURLWithString:urlStr];
NSURLRequest * request = [NSURLRequestrequestWithURL:url];
[_webViewloadRequest:request];
2.加载本地html文件(可加载image)
//baseURL把项目根目录统一中项目下,加载double.html中的image,
css的话,不需要写路径,直接写名字就可以。这样html中的图片就可以正常显示了
NSURL * baseURL = [NSURLfileURLWithPath:[NSBundlemainBundle].bundlePath];
NSString * htmlPath = [[NSBundlemainBundle]pathForResource:@"double"ofType:@"html"];
NSString * htmlCont = [NSStringstringWithContentsOfFile:htmlPathencoding:NSUTF8StringEncodingerror:nil];
[_webViewloadHTMLString:htmlContbaseURL:baseURL];
3.加载[b]加载本地或者从服务器下载的文件,如txt,pdf,word等[/b]
//获取本地文件的url
NSURL * fileURL = [[NSBundlemainBundle]URLForResource:@"LocalFile.txt"withExtension:nil];
NSURLRequest * request = [NSURLRequestrequestWithURL:fileURL];
[_webViewloadRequest:request];
相关文章推荐
- UIWebView 加载网页数据(网页,网页片段,本地文件)
- 使用UIWebView加载本地或远程服务器上的网页
- Swift - 网页控件(UIWebView)加载网页,本地数据,文件
- UIWebView加载网页、html、本地文件、二进制方式加载本地文件
- UIWebView获得网页内容(HTML源码)、加载本地HTML文件
- ios-day20-02(使用UIWebView加载Bundle或者沙盒中的本地文件(PDF、txt、doc))
- Swift - 网页控件(UIWebView)加载本地数据,文件
- iOS UIWebView 加载本地html文件 同时加载javascript文件,javascript文件无效
- Swift - 网页控件(UIWebView)加载本地数据,文件
- 【IOS 开发】UIWebView 加载本地文件,多层的网页目录结构失败分析和解决,以及demo
- IOS中使用UIWebView 加载网页、文件、 html的方法
- UIWebView 本地加载网页和文件(图片素材,js,css)(功能插件化)
- UIWebView获得网页内容(HTML源码)、加载本地HTML文件
- IOS中使用UIWebView 加载网页、文件、 html的方法
- monotouch在使用uiwebview时加载本地html文件时的图片显示
- UIWebView加载本地pdf、doc等文件
- 360chrome,google chrome浏览器使用jquery.ajax加载本地html文件
- ADS分散加载文件使用总结(lpc23xx)
- UIWebView加载本地HTML5文件
- arcgis server 9.3 ADF开发 CAD文件本地动态加载到graphicslayer中总结