【问题标题】:How to align an image in the center in WKWebView objective c如何在 WKWebView 目标 c 中对齐图像中心
【发布时间】:2018-08-08 10:02:36
【问题描述】:

这是我显示图像的代码。

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

【问题讨论】:

  • 您是否尝试过先回答这个问题:如何对齐网页中的图像

标签: ios objective-c iphone webview wkwebview


【解决方案1】:

我看到您的链接指向一个简单的 jpg 图像。 然后,您可以使用

向 WKWebView 提供 html 代码,而不是直接链接到图像
[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 一样设置图像框架(或约束)

【讨论】:

    猜你喜欢
    • 2014-05-29
    • 2019-05-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    相关资源
    最近更新 更多