I am using WKWebView().The size of my webView height = 100. I am loading a .gif image inside WKWebview. The size of gif image height = 300. I want to compress the image inside webview to fit inside it.
AS shown in below screen shot, the image is not shrinking to webView Size,its original size is 300
If i give sixe of WkWebview to 300 , it comes proper
.
I have tried giving
self.webView.contentMode = .scaleAspectFit
self.webView.sizeToFit()
self.webView.autoresizesSubviews = true
self.webView.scrollView.contentInset = UIEdgeInsetsMake(0,0,0,0)
self.webView.scrollView.isScrollEnabled = false
This is the way I am adding the WKWebview:
self.webView = WKWebView()
self.webView.frame = CGRect.init(x: 0, y: 64, width: self.view.frame.width, height:200)
self.webView.autoresizingMask = .flexibleWidth
let heightConstraint = NSLayoutConstraint(item: self.webView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 200)
self.view.addSubview(self.webView)
let filePath = Bundle.main.path(forResource:"token", ofType: "gif")
let gifData = NSData(contentsOfFile: filePath!)
self.webView.load(gifData as! Data, mimeType: "image/gif", characterEncodingName: String(), baseURL: NSURL() as URL)