0

Trying to display the below request.

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)

}

Unfortunately, the image size appering in WKWebview is very huge. Because of that, horizontal scrolling happening. But, i don't want this behaviour.

Expecting the image size should be same fit into WKWebView.

enter image description here

battlmonstr
  • 5,841
  • 1
  • 23
  • 33
Ramdhas
  • 1,765
  • 1
  • 18
  • 26

1 Answers1

1

You could consider one of 2 solutions:

  1. just stretch it using CSS width: 100% (height will be calculated automatically)
  2. use it as a background image for the whole page and stretch it using CSS background-size: 100% or background-size: cover

Actually see this: Stretch and scale a CSS image in the background - with CSS only

battlmonstr
  • 5,841
  • 1
  • 23
  • 33