UIWebView:应用程序文档文件夹中图像的绝对路径 [英] UIWebView: Absolute path for images in app documents folder

查看:90
本文介绍了UIWebView:应用程序文档文件夹中图像的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UIWebView加载一些html。在它是一个img标签,我在应用程序文档文件夹中保存一个图像,我想在HTML中显示该图像,我这样这样

I have a UIWebView that loads up some html. In it is an img tag, I am saving an image in the app documents folder and I want to display that image within the html, I do so like this

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    NSString *tempImgFN = [NSString stringWithFormat:@"tempImg%d.jpg",storyRowID];
    NSString *tempImg = [documentsDir stringByAppendingPathComponent:tempImgFN];

    [imageBlob writeToFile:tempImg atomically:NO];
    tempImg = [tempImg stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
    tempImg = [tempImg stringByReplacingOccurrencesOfString:@" " withString:@"%20"];

    [string appendString:[NSString stringWithFormat:@"<img style='max-width:120px' src=\"%@\" alt=\"\"/>",tempImg]];

imageBlob是一个带有图像数据的NSdata。图像被成功保存,其余的HTML加载好,但图像不显示。

the imageBlob is an NSdata with the data for the image. the image is saved successfully and rest of the html loads up fine but the image is not displayed.

如果我将UIwebView的baseUrl设置为指向文档文件夹,这将很好。但我不想这样做,因为我想baseURL是[NSBundle mainBundle] resourcePath]访问一些javascript文件和css

This works fine if I set the baseUrl of the UIwebView to point to the documents folder. But I don't want to do that because I want the baseURL to be [NSBundle mainBundle] resourcePath] to access some javascript files and css

推荐答案

woops是愚蠢的我..只需要把src = \文件:/%@ \

woops that was stupid of me .. just needed to put src=\"file:/%@\"

这篇关于UIWebView:应用程序文档文件夹中图像的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆