简体   繁体   English

图片不适合网络视图

[英]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 我正在网络视图上显示图像,但无法完全适合网络视图,并且在边框周围显示空白。我如何将图像完全适合或缩放到 在此处输入图片说明 web 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];

Try this html code snippet 试试这个html代码片段

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

It will fill the web view completely without any white space. 它将完全填充Web视图,没有任何空白。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM