0

Am displaying a Image on a web view and it doesn't fit the web view completely and shows blank white space around the border.How can i fit or scale the image completely to the size of enter image description hereweb view?

 NSURL *url = [NSURL fileURLWithPath:path];
        NSURLRequest *request = [NSURLRequest requestWithURL:url];
        [self.webView loadRequest:request];
        self.webView.backgroundColor=[UIColor blackColor];
        self.webView.delegate = self;
        [self.webView setScalesPageToFit:YES];
Kampai
  • 22,848
  • 21
  • 95
  • 95
  • Have a look on this answer - http://stackoverflow.com/questions/26252101/fit-image-of-random-size-into-a-uiwebview-ios/26252838#26252838 – Kampai Nov 27 '14 at 06:06

2 Answers2

1

Try this html code snippet

<html><body><img src='%@' width='100%' height='100%'></body></html>

It will fill the web view completely without any white space.

SS Akhtar
  • 346
  • 2
  • 11
0

try to load like this

 - (void) showImageWithLoadHTMLString {
        // Create URL string for image file location

        NSURL    *imageURL   = [NSURL fileURLWithPath: path];

        // Create HTML string from image URL

        NSString *htmlString = @"<html><body><img src='%@' width='900'></body></html>";
        NSString *imageHTML  = [[NSString alloc] initWithFormat:htmlString, imageURL];

        // Load image in UIWebView
        self.webView.backgroundColor=[UIColor blackColor];
        self.webView.scalesPageToFit = YES;
        [self.webView loadHTMLString:imageHTML baseURL:nil];
    }
Sport
  • 8,570
  • 6
  • 46
  • 65