zoukankan      html  css  js  c++  java
  • UIWebView加载本地网页与图片的方法

     
    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 
     
    感谢您的访问! 若对您有帮助或有兴趣请关注博客:http://www.cnblogs.com/Rong-Shengcom/
  • 相关阅读:
    Linux下安装配置SVN服务器,windows访问
    Zookeeper集群版搭建
    Zookeeper单机版启动
    Nginx-Session缓存一致性-memcached
    Nginx-配置多台Tomcat-反向代理
    Linux-tomcat-安装启动
    Linux-JDK-环境搭建安装
    Nginx-安装-运行访问页面
    Linux-虚拟机-克隆-学习
    解决CocosCreator 在微信小游戏中使用Socket.io 报错的问题
  • 原文地址:https://www.cnblogs.com/Rong-Shengcom/p/5422052.html
Copyright © 2011-2022 走看看