现在的位置: 首页 > 综合 > 正文

在UIWebView中加载本地图片

2013年12月12日 ⁄ 综合 ⁄ 共 486字 ⁄ 字号 评论关闭
NSString *imagePath = [[NSBundle mainBundle] resourcePath];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@"/" withString:@"//"];
imagePath = [imagePath stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSString * js = [NSString stringWithFormat:@"document.images[0].src='file:/%@//%@'",imagePath,@"test.png"];
    
[infoWebView stringByEvaluatingJavaScriptFromString:js];
NSString *path = [infoWebView stringByEvaluatingJavaScriptFromString:@"document.images[0].src"];

像一般情况下一样用file scheme访问就可以了

抱歉!评论已关闭.