zoukankan      html  css  js  c++  java
  • ios加载本地html

     

     

    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);

    }

     

     

  • 相关阅读:
    Linux下配置APUE的编译 报错之后如何处理
    Sed命令的使用详细解释
    Linux下安装xrdp
    CentOS7.1 VNC Server服务配置
    Linux下core文件调试方法
    GDB获取帮助信息
    gdb调试工具学习
    Linux中tftp安装及使用笔记
    CentOS7.3安装Python3.6
    C#语言注释详解
  • 原文地址:https://www.cnblogs.com/xsyl/p/5742394.html
Copyright © 2011-2022 走看看