首页 > Web开发 > 详细

UIWebView加载本地网页与图片的方法

时间:2016-04-22 18:25:21      阅读:267      评论: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);
}


图片+文字是最好的说明,希望可以帮到忙。

图片:CD096BB8-D0C3-48AE-80C1-0CBCEB11C1D9.png 
技术分享
 

UIWebView加载本地网页与图片的方法

原文:http://www.cnblogs.com/Rong-Shengcom/p/5422052.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!