试图显示以下请求。
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相同。
您可以考虑以下两种解决方案之一:
width: 100%
拉伸它(高度将自动计算)background-size: 100%
或background-size: cover
对其进行拉伸>实际上看到此:Stretch and scale a CSS image in the background - with CSS only