UIWebView(一):加载html
来源:互联网 发布:2017淘宝销售排行 编辑:程序博客网 时间:2024/05/16 10:21
UIWebView 加载html 分为以下三种情况:
1,加载网络html:
NSURL *url = [NSURL URLWithString:@"http://localhost:8080/jmDemo/index.html"];NSURLRequest *request = [NSURLRequest requestWithURL:url];[_webView loadRequest:request];
2,加载本地html,文件在文件项目中;
NSURL *baseURL = [NSURL fileURLWithPath:[[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"assets"]];NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"htm" inDirectory:@"assets"];NSString *htmlString = [[[NSString alloc] initWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil] autorelease]; [_webView loadHTMLString:htmlString baseURL:baseURL];
注意:此处将html 文件夹拖入工程目录时要选择,见下图:
拖进去后在工程目录显示蓝色的文件夹:
这样拖进去的html文件夹,在打包成.app工程包后仍会保持原来的文件结构,html文件在app运行时引用图片等相关资源不会出问题。
3,加载本地html,文件在文件Document中;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *documentsDirectory = [paths objectAtIndex:0];NSString *path = [documentsDirectory stringByAppendingPathComponent:@"index.html"];NSURL *url = [NSURL fileURLWithPath:path];NSURLRequest *request = [NSURLRequest requestWithURL:url];[_webView loadRequest:request];
0 0
- UIWebView(一):加载html
- ios UIWebView加载html(详解)
- UIWebView加载html
- uiwebView 加载html字符串
- UIWebView加载html
- UIWebView加载本地html
- UIWebView加载本地html
- UIWebView 加载 HTML
- uiwebview加载html代码
- UIWebView加载本地html
- UIWebView加载本地html
- UIWebView加载html标签
- UIWebView加载html(转)
- UIWebView加载本地HTML文件
- UIWebView加载本地html ios
- UIwebview加载本地html文件
- html代码加载到UIWebView
- UIWebView加载本地HTML文件
- ios UIWebView 加载网页、文件、 html
- 四川省ACM竞赛(2013)---G-Good Numbers(规律/可DP)
- 地址总线,字长,内存容量,寻址范围 之间的计算
- 不为了没完没了的工作
- C++浅复制 多态 友元 纯虚函数虚类
- UIWebView(一):加载html
- web前端
- 利用stm32f103的TIM2实现精确延时
- 就为了拥抱春天的快乐,
- ios 屏幕适配
- Tomcat 内存溢出问题
- 剑指Offer之 - 复杂链表的复制
- 就为了播种绿色的心愿
- matlab实现图像校正