码迷,mamicode.com
首页 > 移动开发 > 详细

ios加载本地html

时间:2016-08-05 19:37:04      阅读:245      评论:0      收藏:0      [点我收藏+]

标签:

 

 

UIWebView加载工程本地网页与本地图片

 

- (void)viewDidLoad

{

    [super viewDidLoad];

    

    NSString *filePath = [[NSBundle mainBundle]pathForResource:@"1" ofType:@"html"];

    NSString *htmlString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];

    

    myWebView = [[UIWebView alloc] initWithFrame:self.view.bounds];

    myWebView.delegate = self;

    [self.view addSubview:myWebView];

    

    [myWebView loadHTMLString:htmlString baseURL:[NSURL URLWithString:filePath]];

    

}

 

-(void)webViewDidFinishLoad:(UIWebView *)webView

{

    NSString *imagePath = [[NSBundle mainBundle] resourcePath];

    imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];

    imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

    NSString * js = [NSString stringWithFormat:@"document.images[0].src=‘file:/%@//%@‘",imagePath,@"icon-04.png"];

    

    [myWebView stringByEvaluatingJavaScriptFromString:js];

    NSString *path = [myWebView stringByEvaluatingJavaScriptFromString:@"document.images[0].src"];

    NSLog(@"path:%@", path);

}

 

 

ios加载本地html

标签:

原文地址:http://www.cnblogs.com/xsyl/p/5742394.html

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