Note that there are some explanatory texts on larger screens.

plurals
  1. POReplacing image source with UIImage in UIWebiew
    primarykey
    data
    text
    <p>I am writing an application that parses a HTML string embedded with images and data. I am able to use SDWebImage to cache the images part for later use and it is caching perfectly. However, I need to use the cached image (UIImage) as a replacement for the src in the html string. I think this can be done with some javascript code but I am a total duffer when it comes to javascript and css. Can someone give me some javascript code to change the image src to this UIImage?</p> <p>Code to cache image:</p> <pre><code>-(NSString *)fetchImageUrlFromSummary:(NSString *)summaryData { NSError *error = nil; NSString *urlString = [NSString string]; HTMLParser *parser = [[HTMLParser alloc]initWithString:summaryData error:&amp;error]; if (error) { NSLog(@"%@", error); return nil; } HTMLNode *bodyNode = [parser body]; NSArray *inputNodes = [bodyNode findChildTags:@"img"]; for (HTMLNode *inputNode in inputNodes) { //NSLog(@"%@", [inputNode getAttributeNamed:@"src"]); if ([[inputNode getAttributeNamed:@"src"]hasSuffix:@"png"] || [[inputNode getAttributeNamed:@"src"]hasSuffix:@"jpg"]|| [[inputNode getAttributeNamed:@"src"]hasSuffix:@"jpeg"]) { urlString = [inputNode getAttributeNamed:@"src"]; [SDWebImagePrefetcher.sharedImagePrefetcher prefetchURLs:[NSArray arrayWithObject:urlString]]; } } return urlString; } </code></pre> <p>Code to set the summary string in uiwebview:</p> <pre><code>NSString *summaryString = [[NSString alloc]initWithData:[_htmlData summary] encoding:NSUTF8StringEncoding]; NSString *myDescriptionHTML = [NSString stringWithFormat:@"&lt;html&gt;&lt;head&gt;&lt;style type=\"text/css\"&gt; div{text-align:justify;text-justify:inter-word;margin:auto} img {max-width:100%%;width:auto;height:auto;}body{font-family: Verdana;font-size: 12pt;max-width: 100%%; width:auto; height:auto;} &lt;body bgcolor=\"#F5F5DC\"&gt;&lt;/style&gt;&lt;body&gt;%@&lt;/body&gt;&lt;/html&gt;", summaryString]; [_webView loadHTMLString:myDescriptionHTML baseURL:[NSURL URLWithString:[_htmlData originUrl]]]; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload