我想使用UIWebView加载html网址,但不要在html中加载图片。我希望UIWebView只显示html中的纯文本。由于某种原因,我无法在加载前更改html内容。
有没有办法实现这个目标?
答案 0 :(得分:2)
- (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
的部分代码希望它会有所帮助
答案 1 :(得分:0)
Then remove all image tages using below code then after load your html string into webview
NSString *str =@"<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);