2012-03-20 2 views
3

Я хочу использовать UIWebView для загрузки html-url, но не загружаю изображение в html. Я хочу, чтобы UIWebView отображал только обычный текст в html. По какой-то причине я не могу изменить содержимое html перед загрузкой.Как остановить загрузку изображений в UIWebView?

Есть ли способ достичь этого?

+0

вы можете представить, что формат HTML строки – Narayana

+0

Может быть, вы можете использовать этот http://stackoverflow.com/questions/2067943/iphone-СДК-сказать-UIWebView-не-к-багажных изображений-и-CSS-просто-льняной HTML-и-JS. – simonbs

+0

Это может помочь вам: [Остановка загрузки изображений] [1] [1]: http://stackoverflow.com/questions/2598833/stop-images-from-loading-in- uiwebview –

ответ

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

Надежда это поможет

0
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); 
+0

Есть способы загрузки изображения без статического тега img в исходном коде, в том числе через JavaScript и CSS. – titaniumdecoy

Смежные вопросы