繁体   English   中英

图片不适合网络视图

[英]Image doesn't fit 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];

试试这个html代码片段

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

它将完全填充Web视图,没有任何空白。

尝试像这样加载

 - (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