本文介绍了从.html文件在Web视图中加载图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从.html文件在iPhone Webview中加载图像?

How can I load an image in iphone webview from a .html file?

推荐答案

简单

NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
    NSURL *bundleBaseURL = [NSURL fileURLWithPath: bundlePath];

    NSLog(@"webview %@", bundlePath);


    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];
    NSData *htmlData = [NSData dataWithContentsOfFile:filePath];
    NSString * html =  [NSString stringWithContentsOfFile:filePath encoding:NSStringEncodingConversionAllowLossy error:nil];
    if (htmlData) {
       [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:bundleBaseURL];
    }

现在在您的html中,您可以将图片简称为

Now in your html you can simply refer to the image as

这篇关于从.html文件在Web视图中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 21:34