Set Minimum and Maximum Zoom on WKWebView or Disabling it entirely












0














What I want:



I'm trying to figure out how to set the minimum and maximum zoom onWKWebView.
I've searched through a lot of people who asked similar questions but no solutions has worked in my code.
If there is no option to set the minimum and maximum zoom, I would like to know how to disable zoom on WKWebView entirely.



    import UIKit
import WebKit

class CalendarViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

var webView: WKWebView!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var progressView: UIProgressView!

override func loadView() {
super.loadView()
}

override func viewDidLoad() {
super.viewDidLoad()


progressView.setProgress(0.1, animated: true)

let webConfiguration = WKWebViewConfiguration()
webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"

let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.containerView.frame.size.height))

webView = WKWebView(frame: customFrame, configuration: webConfiguration)
webView.uiDelegate = self
webView.navigationDelegate = self
self.containerView.addSubview(webView)
self.webView.translatesAutoresizingMaskIntoConstraints = false

self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: self.containerView, attribute: .trailing, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: self.containerView, attribute: .leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: self.containerView, attribute: .top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: self.containerView, attribute: .bottom, multiplier: 1, constant: 0))



progressView.sizeToFit()
progressView.progressTintColor = UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1.0)

webView.backgroundColor = UIColor.clear
webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)
webView.isOpaque = false

webView.load(URLRequest(url: URL(string: "https://jwelsh19.wixsite.com/website-1")!))

self.webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)

//create a new button
let button = UIButton.init(type: .custom)
//set image for button
button.setImage(UIImage(named: "LogoMin"), for: UIControlState.normal)
//add function for button
button.addTarget(self, action: #selector(SportsViewController.acButtonPressed), for: UIControlEvents.touchUpInside)
//set frame
button.frame = CGRect(x: 0, y: 0, width: 32, height: 32)
button.widthAnchor.constraint(equalToConstant: 32.0).isActive = true
button.heightAnchor.constraint(equalToConstant: 32.0).isActive = true

let barButton = UIBarButtonItem(customView: button)
//assign button to navigationbar
self.navigationItem.leftBarButtonItem = barButton

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(reloadWebView(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor.white
webView.scrollView.addSubview(refreshControl)
}

@objc func reloadWebView(_ sender: UIRefreshControl) {
webView.reload()
sender.endRefreshing()
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
print(self.webView.estimatedProgress);
self.progressView.progress = Float(self.webView.estimatedProgress); }
}

@IBAction func home(_ sender: UIButton) {
let myURL = URL(string: "https://jwelsh19.wixsite.com/website-1")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}

@IBAction func refresh(_ sender: UIButton) {

webView.reload()

}

//This method will call when you press button.
@objc func acButtonPressed() {

print("button is pressed")
self.performSegue(withIdentifier: "Account", sender: self)
}
}









share|improve this question
























  • possible duplicate of stackoverflow.com/questions/46289653/…
    – Alex Bailey
    Nov 14 '18 at 2:22










  • No answer to the question on that page
    – Nigel Denny
    Nov 14 '18 at 2:58










  • Do you have control of the HTML you are displaying?
    – Spads
    Nov 17 '18 at 13:31










  • I don't have control...
    – Nigel Denny
    Nov 19 '18 at 6:05
















0














What I want:



I'm trying to figure out how to set the minimum and maximum zoom onWKWebView.
I've searched through a lot of people who asked similar questions but no solutions has worked in my code.
If there is no option to set the minimum and maximum zoom, I would like to know how to disable zoom on WKWebView entirely.



    import UIKit
import WebKit

class CalendarViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

var webView: WKWebView!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var progressView: UIProgressView!

override func loadView() {
super.loadView()
}

override func viewDidLoad() {
super.viewDidLoad()


progressView.setProgress(0.1, animated: true)

let webConfiguration = WKWebViewConfiguration()
webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"

let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.containerView.frame.size.height))

webView = WKWebView(frame: customFrame, configuration: webConfiguration)
webView.uiDelegate = self
webView.navigationDelegate = self
self.containerView.addSubview(webView)
self.webView.translatesAutoresizingMaskIntoConstraints = false

self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: self.containerView, attribute: .trailing, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: self.containerView, attribute: .leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: self.containerView, attribute: .top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: self.containerView, attribute: .bottom, multiplier: 1, constant: 0))



progressView.sizeToFit()
progressView.progressTintColor = UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1.0)

webView.backgroundColor = UIColor.clear
webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)
webView.isOpaque = false

webView.load(URLRequest(url: URL(string: "https://jwelsh19.wixsite.com/website-1")!))

self.webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)

//create a new button
let button = UIButton.init(type: .custom)
//set image for button
button.setImage(UIImage(named: "LogoMin"), for: UIControlState.normal)
//add function for button
button.addTarget(self, action: #selector(SportsViewController.acButtonPressed), for: UIControlEvents.touchUpInside)
//set frame
button.frame = CGRect(x: 0, y: 0, width: 32, height: 32)
button.widthAnchor.constraint(equalToConstant: 32.0).isActive = true
button.heightAnchor.constraint(equalToConstant: 32.0).isActive = true

let barButton = UIBarButtonItem(customView: button)
//assign button to navigationbar
self.navigationItem.leftBarButtonItem = barButton

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(reloadWebView(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor.white
webView.scrollView.addSubview(refreshControl)
}

@objc func reloadWebView(_ sender: UIRefreshControl) {
webView.reload()
sender.endRefreshing()
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
print(self.webView.estimatedProgress);
self.progressView.progress = Float(self.webView.estimatedProgress); }
}

@IBAction func home(_ sender: UIButton) {
let myURL = URL(string: "https://jwelsh19.wixsite.com/website-1")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}

@IBAction func refresh(_ sender: UIButton) {

webView.reload()

}

//This method will call when you press button.
@objc func acButtonPressed() {

print("button is pressed")
self.performSegue(withIdentifier: "Account", sender: self)
}
}









share|improve this question
























  • possible duplicate of stackoverflow.com/questions/46289653/…
    – Alex Bailey
    Nov 14 '18 at 2:22










  • No answer to the question on that page
    – Nigel Denny
    Nov 14 '18 at 2:58










  • Do you have control of the HTML you are displaying?
    – Spads
    Nov 17 '18 at 13:31










  • I don't have control...
    – Nigel Denny
    Nov 19 '18 at 6:05














0












0








0


1





What I want:



I'm trying to figure out how to set the minimum and maximum zoom onWKWebView.
I've searched through a lot of people who asked similar questions but no solutions has worked in my code.
If there is no option to set the minimum and maximum zoom, I would like to know how to disable zoom on WKWebView entirely.



    import UIKit
import WebKit

class CalendarViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

var webView: WKWebView!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var progressView: UIProgressView!

override func loadView() {
super.loadView()
}

override func viewDidLoad() {
super.viewDidLoad()


progressView.setProgress(0.1, animated: true)

let webConfiguration = WKWebViewConfiguration()
webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"

let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.containerView.frame.size.height))

webView = WKWebView(frame: customFrame, configuration: webConfiguration)
webView.uiDelegate = self
webView.navigationDelegate = self
self.containerView.addSubview(webView)
self.webView.translatesAutoresizingMaskIntoConstraints = false

self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: self.containerView, attribute: .trailing, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: self.containerView, attribute: .leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: self.containerView, attribute: .top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: self.containerView, attribute: .bottom, multiplier: 1, constant: 0))



progressView.sizeToFit()
progressView.progressTintColor = UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1.0)

webView.backgroundColor = UIColor.clear
webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)
webView.isOpaque = false

webView.load(URLRequest(url: URL(string: "https://jwelsh19.wixsite.com/website-1")!))

self.webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)

//create a new button
let button = UIButton.init(type: .custom)
//set image for button
button.setImage(UIImage(named: "LogoMin"), for: UIControlState.normal)
//add function for button
button.addTarget(self, action: #selector(SportsViewController.acButtonPressed), for: UIControlEvents.touchUpInside)
//set frame
button.frame = CGRect(x: 0, y: 0, width: 32, height: 32)
button.widthAnchor.constraint(equalToConstant: 32.0).isActive = true
button.heightAnchor.constraint(equalToConstant: 32.0).isActive = true

let barButton = UIBarButtonItem(customView: button)
//assign button to navigationbar
self.navigationItem.leftBarButtonItem = barButton

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(reloadWebView(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor.white
webView.scrollView.addSubview(refreshControl)
}

@objc func reloadWebView(_ sender: UIRefreshControl) {
webView.reload()
sender.endRefreshing()
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
print(self.webView.estimatedProgress);
self.progressView.progress = Float(self.webView.estimatedProgress); }
}

@IBAction func home(_ sender: UIButton) {
let myURL = URL(string: "https://jwelsh19.wixsite.com/website-1")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}

@IBAction func refresh(_ sender: UIButton) {

webView.reload()

}

//This method will call when you press button.
@objc func acButtonPressed() {

print("button is pressed")
self.performSegue(withIdentifier: "Account", sender: self)
}
}









share|improve this question















What I want:



I'm trying to figure out how to set the minimum and maximum zoom onWKWebView.
I've searched through a lot of people who asked similar questions but no solutions has worked in my code.
If there is no option to set the minimum and maximum zoom, I would like to know how to disable zoom on WKWebView entirely.



    import UIKit
import WebKit

class CalendarViewController: UIViewController, WKNavigationDelegate, WKUIDelegate {

var webView: WKWebView!
@IBOutlet weak var containerView: UIView!
@IBOutlet weak var progressView: UIProgressView!

override func loadView() {
super.loadView()
}

override func viewDidLoad() {
super.viewDidLoad()


progressView.setProgress(0.1, animated: true)

let webConfiguration = WKWebViewConfiguration()
webConfiguration.applicationNameForUserAgent = "Version/8.0.2 Safari/600.2.5"

let customFrame = CGRect.init(origin: CGPoint.zero, size: CGSize.init(width: 0.0, height: self.containerView.frame.size.height))

webView = WKWebView(frame: customFrame, configuration: webConfiguration)
webView.uiDelegate = self
webView.navigationDelegate = self
self.containerView.addSubview(webView)
self.webView.translatesAutoresizingMaskIntoConstraints = false

self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .trailing, relatedBy: .equal, toItem: self.containerView, attribute: .trailing, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .leading, relatedBy: .equal, toItem: self.containerView, attribute: .leading, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .top, relatedBy: .equal, toItem: self.containerView, attribute: .top, multiplier: 1, constant: 0))
self.view.addConstraint(NSLayoutConstraint(item: webView, attribute: .bottom, relatedBy: .equal, toItem: self.containerView, attribute: .bottom, multiplier: 1, constant: 0))



progressView.sizeToFit()
progressView.progressTintColor = UIColor(red: 255/255, green: 204/255, blue: 0/255, alpha: 1.0)

webView.backgroundColor = UIColor.clear
webView.backgroundColor = UIColor(red: 0.0196, green: 0.4, blue: 0.2902, alpha: 1.0)
webView.isOpaque = false

webView.load(URLRequest(url: URL(string: "https://jwelsh19.wixsite.com/website-1")!))

self.webView.addObserver(self, forKeyPath: "estimatedProgress", options: .new, context: nil)

//create a new button
let button = UIButton.init(type: .custom)
//set image for button
button.setImage(UIImage(named: "LogoMin"), for: UIControlState.normal)
//add function for button
button.addTarget(self, action: #selector(SportsViewController.acButtonPressed), for: UIControlEvents.touchUpInside)
//set frame
button.frame = CGRect(x: 0, y: 0, width: 32, height: 32)
button.widthAnchor.constraint(equalToConstant: 32.0).isActive = true
button.heightAnchor.constraint(equalToConstant: 32.0).isActive = true

let barButton = UIBarButtonItem(customView: button)
//assign button to navigationbar
self.navigationItem.leftBarButtonItem = barButton

let refreshControl = UIRefreshControl()
refreshControl.addTarget(self, action: #selector(reloadWebView(_:)), for: .valueChanged)
refreshControl.tintColor = UIColor.white
webView.scrollView.addSubview(refreshControl)
}

@objc func reloadWebView(_ sender: UIRefreshControl) {
webView.reload()
sender.endRefreshing()
}

override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "estimatedProgress" {
print(self.webView.estimatedProgress);
self.progressView.progress = Float(self.webView.estimatedProgress); }
}

@IBAction func home(_ sender: UIButton) {
let myURL = URL(string: "https://jwelsh19.wixsite.com/website-1")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}

@IBAction func refresh(_ sender: UIButton) {

webView.reload()

}

//This method will call when you press button.
@objc func acButtonPressed() {

print("button is pressed")
self.performSegue(withIdentifier: "Account", sender: self)
}
}






ios swift zoom wkwebview pinchzoom






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 14 '18 at 3:39









Homam

192




192










asked Nov 14 '18 at 0:09









Nigel Denny

697




697












  • possible duplicate of stackoverflow.com/questions/46289653/…
    – Alex Bailey
    Nov 14 '18 at 2:22










  • No answer to the question on that page
    – Nigel Denny
    Nov 14 '18 at 2:58










  • Do you have control of the HTML you are displaying?
    – Spads
    Nov 17 '18 at 13:31










  • I don't have control...
    – Nigel Denny
    Nov 19 '18 at 6:05


















  • possible duplicate of stackoverflow.com/questions/46289653/…
    – Alex Bailey
    Nov 14 '18 at 2:22










  • No answer to the question on that page
    – Nigel Denny
    Nov 14 '18 at 2:58










  • Do you have control of the HTML you are displaying?
    – Spads
    Nov 17 '18 at 13:31










  • I don't have control...
    – Nigel Denny
    Nov 19 '18 at 6:05
















possible duplicate of stackoverflow.com/questions/46289653/…
– Alex Bailey
Nov 14 '18 at 2:22




possible duplicate of stackoverflow.com/questions/46289653/…
– Alex Bailey
Nov 14 '18 at 2:22












No answer to the question on that page
– Nigel Denny
Nov 14 '18 at 2:58




No answer to the question on that page
– Nigel Denny
Nov 14 '18 at 2:58












Do you have control of the HTML you are displaying?
– Spads
Nov 17 '18 at 13:31




Do you have control of the HTML you are displaying?
– Spads
Nov 17 '18 at 13:31












I don't have control...
– Nigel Denny
Nov 19 '18 at 6:05




I don't have control...
– Nigel Denny
Nov 19 '18 at 6:05

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291300%2fset-minimum-and-maximum-zoom-on-wkwebview-or-disabling-it-entirely%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53291300%2fset-minimum-and-maximum-zoom-on-wkwebview-or-disabling-it-entirely%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)