I was wondering if there was a way in Swift
to check if the user has clicked a link in the website displayed via the webView
, and then change how much of the website is showing.
For example if I was on cnn.com
, and then clicked on an article, I would like it if there was a way to click the link, and then cut off part of the top of the website and bottom of the website, making only part of the website viewable(the article).
I mainly just want to know if there is a statement you can use to see if the user clicked a link in the webview, and then do something if the user has clicked a link.
You can use UIWebViewDelegate
method shouldStartLoadWith(request: navigationType:)
and check navigationType to check if the link is clicked. Second part(cut off part of the top of the website and bottom of the website on link click) depends on how the page loading and navigation handled inside the webpage
func webView(_ webView: UIWebView, shouldStartLoadWith request: URLRequest, navigationType: UIWebViewNavigationType) -> Bool {
switch navigationType {
case .linkClicked:
//do something
default:
break
}
return true
}