码迷,mamicode.com
首页 > 编程语言 > 详细

0521.使用UIWebView加载来自NetWork、Project、Documents的html、javascript文件

时间:2014-05-22 23:53:05      阅读:442      评论:0      收藏:0      [点我收藏+]

标签:iphone应用   ios开发   ios   html   


话不多少,直接上代码,思路还是挺简单的。


    UIWebView *webView = [[UIWebView alloc]initWithFrame:self.view.frame];
    
    // HTML文件来自Project
    // 步骤:path - > url - > request with url - > loadRequest
    NSString *path_Proj = [[NSBundle mainBundle]pathForResource:@"index" ofType:@"html"];
    NSURL *url_Proj = [NSURL fileURLWithPath:path_Proj];
    NSURLRequest *request_local = [NSURLRequest requestWithURL:url_Proj];
    [webView loadRequest:request_local];
    
    // HTML文件来自Documents
    // 步骤:pathArrary - > path - > url - > request with url - > loadRequest
    NSArray *pathArrary = NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [pathArrary objectAtIndex:0];
    NSString *path_Doc = [documentsDirectory stringByAppendingPathComponent:@"index.html"];
    NSURL *url_Doc = [NSURL fileURLWithPath:path_Doc];
    NSURLRequest *request_Doc = [NSURLRequest requestWithURL:url_Doc];
    [webView loadRequest:request_Doc];
    
    // HTML文件来自Network
    // 步骤:url - > request with url - > loadRequest
    NSURL *url_net = [NSURL URLWithString:@"http://文件地址/index.html"];
    NSURLRequest *request_net = [NSURLRequest requestWithURL:url_net];
    [webView loadRequest:request_net];


0521.使用UIWebView加载来自NetWork、Project、Documents的html、javascript文件,布布扣,bubuko.com

0521.使用UIWebView加载来自NetWork、Project、Documents的html、javascript文件

标签:iphone应用   ios开发   ios   html   

原文地址:http://blog.csdn.net/paulery2012/article/details/26503273

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!