我想使用UIWebView来加载一个HTML网址,但不要在HTML中加载图像。我想要UIWebView只是在html中显示纯文本。由于某种原因,我无法在加载前更改html内容。如何停止在UIWebView中加载图像?
有没有什么方法可以达到这个目的?
我想使用UIWebView来加载一个HTML网址,但不要在HTML中加载图像。我想要UIWebView只是在html中显示纯文本。由于某种原因,我无法在加载前更改html内容。如何停止在UIWebView中加载图像?
有没有什么方法可以达到这个目的?
- (NSCachedURLResponse*)cachedResponseForRequest:(NSURLRequest*)request
{
NSURL *url = [request URL];
BOOL blockURL = [[FilterMgr sharedFilterMgr] shouldBlockURL:url];
if (blockURL) {
NSURLResponse *response =
[[NSURLResponse alloc] initWithURL:url
MIMEType:@"text/plain"
expectedContentLength:1
textEncodingName:nil];
NSCachedURLResponse *cachedResponse =
[[NSCachedURLResponse alloc] initWithResponse:response
data:[NSData dataWithBytes:" " length:1]];
[super storeCachedResponse:cachedResponse forRequest:request];
[cachedResponse release];
[response release];
}
return [super cachedResponseForRequest:request];
}
它从this
某部分代码,希望对大家有所帮助
Then remove all image tages using below code then after load your html string into webview
NSString *str [email protected]"<ul><img src=\"some url\"/><li>Tiny pores in leaves or stems, which water and gas can pass. </li><li>Plants can reduce the amount of water that is passed by closing the stomates during the hottest parts of the day or curling their leaves up to reduce exposure.</li></ul>";
NSLog(@"before--%@",str);
NSRange r;
while ((r = [str rangeOfString:@"<img[^>]+>" options:NSRegularExpressionSearch]).location != NSNotFound)
str = [str stringByReplacingCharactersInRange:r withString:@""];
NSLog(@"after---%@",str);
有些方法可以在源代码中加载图像,而不需要静态img标签,包括通过JavaScript和CSS。 – titaniumdecoy 2012-04-19 22:52:48
您可以提供HTML字符串格式 – Narayana 2012-03-20 08:53:43
也许你可以使用这个http://stackoverflow.com/questions/2067943/iphone-SDK-告诉-的UIWebView而不是到负载的图像,和CSS-刚刚纯HTML和JS的。 – simonbs 2012-03-20 08:54:21
这可以帮助你: [停止加载图片] [1] [1]:http://stackoverflow.com/questions/2598833/stop-images-from-loading-in- uiwebview – 2012-03-20 08:55:30