【发布时间】:2011-03-15 07:47:30
【问题描述】:
我有一个加载一些 html 的 UIWebView。它是一个 img 标签,我在 app 文档文件夹中保存了一张图片,我想在 html 中显示该图片,我这样做是这样的
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 加载正常,但未显示图像。
如果我将 UIwebView 的 baseUrl 设置为指向文档文件夹,这可以正常工作。但我不想这样做,因为我希望 baseURL 是 [NSBundle mainBundle] resourcePath] 以访问一些 javascript 文件和 css
【问题讨论】:
标签: iphone objective-c cocoa-touch