我想使用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