puneetha koopadira
puneetha koopadira

Reputation: 89

Image doesn't fit web view

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];

Upvotes: 0

Views: 540

Answers (2)

SS Akhtar
SS Akhtar

Reputation: 346

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.

Upvotes: 1

Sport
Sport

Reputation: 8945

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];
    }

Upvotes: 0

Related Questions