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

    }

     

     

  • 相关阅读:
    maven中使用命令下载指定pom.xml中的jar文件
    资源监控平台
    PerfDog的使用教程
    compile ffmepg with amr
    matplotlib
    总线通信
    阿里云NAS文件迁移项目实践
    React diff算法
    IDE Eval Resetter:JetBrains 全家桶无限试用插件
    IntelliJ IDEA 2021.2.0 官方正版
  • 原文地址:https://www.cnblogs.com/xsyl/p/5742394.html
Copyright © 2020-2023  润新知