2011-07-30 回答
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);
}