这是我用来显示图像的代码。
NSString *doc = @"http://13.232.1.87:3000/images/flights/bc4952c8ec51588cdbd72d91c4e1533562273837.jpeg";
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:[NSURL URLWithString:doc]];
[webView loadRequest:nsrequest];
[self.view addSubview:webView];发布于 2018-08-08 21:08:11
我看到你的链接指向一个简单的jpg图像。然后,您可以使用html代码来提供WKWebView,而不是直接链接到图像
[webView loadHTMLString:@"<html>...</html>" baseURL:nil];编辑,或者,如果链接总是指向图像,您甚至可以考虑不使用WKWebView来替换为UIImage:
NSURL *url = [NSURL URLWithString:doc];
NSData *imageData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imageData];或者,为简短起见:
UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:doc]]];然后设置图像框架(或约束),就像使用WKWebView一样
https://stackoverflow.com/questions/51743893
复制相似问题