我在网页视图上显示图片并且它不完全适合网页视图并在边框周围显示空白空白。如何将图像完全适合或缩放到的大小网络视图?
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];
答案 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];
}