In swift 2.1, Xcode7.1.1
My code loads a local index.html into a WKwebView. How can I have a reference to the textFields so that I can set some of their properties? like myWebViewTextField.userInteractionEnabled = false
or myWebViewTextField.enabled = false
The docs says:
You get a window WebScriptObject object by sending windowScriptObject to your WebView object.
I am not sure how to go from here. Thank
import UIKit
import WebKit
class ViewController: UIViewController {
@IBOutlet var containerView: UIView! = nil //allows the class to refrence WKWebView
var webView: WKWebView?
override func loadView() {
super.loadView()
self.webView = WKWebView()
self.view = self.webView!
}
override func viewDidLoad() {
super.viewDidLoad()
//path explained http://www.cs.tut.fi/~jkorpela/fileurl.html
let baseUrl = NSURL(string: "file:///<path>/")
let path = NSBundle.mainBundle().pathForResource("index", ofType: "html")
let HTMLString: NSString?
do {
HTMLString = try NSString(contentsOfFile: path!, encoding: NSUTF8StringEncoding)
webView!.loadHTMLString(HTMLString as! String, baseURL: baseUrl )
} catch {
HTMLString = nil
}
}