I am using wkwebview to show a webpage but it is overlaying the toolbar. If I remove
view = webView Then the toolbar can be seen but not the webpage. Been going around in circles with this and tried several possible solutions in other threads but nothing is working. Here is my code...
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate{
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string:"website address")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
}
}
Related
It is possible to show websites with the help of UIKit and a WKWebView in SwiftUI:
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string: "http://bla.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}
}
I know that you can disable cookies by writing:
myRequest.httpShouldHandleCookies = false
But is there a way to avoid showing the pop up window on websites and reject all cookies that are not needed?
First of all I'm new in swift. I have a WebView app for iOS device using swift language , can add button back to previous page ?
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
var webView: WKWebView!
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://google.com/")!
webView.load(URLRequest(url: url))
webView.allowsBackForwardNavigationGestures = true
let statusBarFrame = UIApplication.shared.statusBarFrame
let statusBarView = UIView(frame: statusBarFrame)
self.view.addSubview(statusBarView)
statusBarView.backgroundColor = .systemBackground
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
title = webView.title
}
}
I have used the following code to create a webView app in swift. but I need to also add a navigation bar at the bottom that goes to different pages of the website. And those are just another link but the webView is taking the whole screen and I can't seem to add the Nav bar to it. Help is appreciated in advance.
import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {
#IBAction func goBack(_ sender: Any) {
self.webView.goBack()
}
var webView: WKWebView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
let myURL = URL(string:"https://test.com")
let myRequest = URLRequest(url: myURL!)
webView.load(myRequest)
}}
In Xib or storyboard add a subview to the bottom And change web view bottom constraint constant value.
WebView constraint
SubView constraint
Pretty new to swift & xcode 9. I have my webview code working and displaying the proper link, but it opens the app with it. I have a few different controllers before it should be displayed (ultimately button triggered). When I have this code in, it doesn't change the default view controller as link, it simply loads the webview right away. Any help would be greatly appreciated!
import UIKit
import WebKit
class ViewController: UIViewController, WKNavigationDelegate {
override func loadView() {
webView = WKWebView()
webView.navigationDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// 1
let url = URL(string: "https://google.com")!
webView.load(URLRequest(url: url))
// 2
let refresh = UIBarButtonItem(barButtonSystemItem: .refresh, target: webView, action: #selector(webView.reload))
toolbarItems = [refresh]
navigationController?.isToolbarHidden = false
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
title = webView.title
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I am making simple web based application where I want to disable all the links when the page is loaded fully into the webView and for that I also tried this answer. But when I try this my UIActivityIndicatorView is stopped displaying.
This is my code:
import UIKit
class ViewController: UIViewController,UIWebViewDelegate {
#IBOutlet var webView: UIWebView!
#IBOutlet weak var Activity: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
Activity.hidden = true
var myString = "https://developer.apple.com/library/mac/documentation/Swift/Conceptual/Swift_Programming_Language/TheBasics.html#//apple_ref/doc/uid/TP40014097-CH5-XID_456"
let myURL = NSURL(string: myString)
let myReq = NSURLRequest(URL: myURL!)
webView.loadRequest(myReq)
webView.delegate = self
}
func webViewDidStartLoad(webView: UIWebView){
var activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
var activityBarButtonItem = UIBarButtonItem(customView: activityIndicator)
navigationItem.rightBarButtonItem = activityBarButtonItem
activityIndicator.startAnimating()
}
func webViewDidFinishLoad(webView: UIWebView){
navigationItem.rightBarButtonItem = nil
}
}
Can anybody tell me how can I achieve that?
Thanks In advance!
What about displaying a transparent view over it?
EDIT
Try adding a new gesture recognizer to it and tell it to do nothing for taps?
let recognizer = UITapGestureRecognizer(target: self, action:Selector("handleTouch:"))
recognizer.delegate = self
webView.addGestureRecognizer(newTap)
func handleTouch(recognizer:UIPanGestureRecognizer) {}
Theres a great tut on gestures in swift here Swifty_Gestures