【问题标题】:Image not fitting into WKWebView图像不适合 WKWebView
【发布时间】:2019-11-03 18:38:15
【问题描述】:

尝试显示以下请求。

class ViewController: UIViewController, WKNavigationDelegate {

@IBOutlet weak var webView: WKWebView!
override func viewDidLoad() {
    super.viewDidLoad()
    webView.navigationDelegate = self
    let htmlString = "<p><a href=\"https://miro.medium.com/max/3336/1*iGyyen2re8-dgQJlL65axw.png\"><img src=\"https://miro.medium.com/max/3336/1*iGyyen2re8-dgQJlL65axw.png\" class=\"alignnone size-full\"></a></p>\n<p></p>\n<p>Vijay Chandrasekhar: \"Robin Uthappa, Faiz Gaza's have already users kookaburra bats before in an international game\"<br><br>Sivan dune just got his t29I cap from Ravi Shastri. He becomes the 82nd cricketer to represent Indian in the format. </p>"
    var headerString = "<header><meta name='viewport' content='width=device-width, initial-scale=0.65, maximum-scale=0.65, minimum-scale=0.65'></header>"
    headerString.append(htmlString)
    webView.loadHTMLString(headerString, baseURL: nil)

}

不幸的是,WKWebview 中出现的图像尺寸非常大。因此,发生了水平滚动。但是,我不想要这种行为。

期望图像大小应该与 WKWebView 相同。

【问题讨论】:

    标签: html ios css wkwebview


    【解决方案1】:

    您可以考虑以下两种解决方案之一:

    1. 只需使用 CSS width: 100% 拉伸它(高度将自动计算)
    2. 将其用作整个页面的背景图像并使用 CSS background-size: 100% 或 background-size: cover 拉伸它

    其实看到这个: Stretch and scale a CSS image in the background - with CSS only

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多