图像不适合Web视图

时间:2014-11-27 05:37:41

标签: ios image uiwebview nsurl

我在网页视图上显示图片并且它不完全适合网页视图并在边框周围显示空白空白。如何将图像完全适合或缩放到enter image description here的大小网络视图?

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

2 个答案:

答案 0 :(得分:1)

试试这个html代码段

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

它将完全填满网页视图,没有任何空格。

答案 1 :(得分:0)

尝试像这样加载

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