问题
I am trying to create an iPhone app with two WKWebView, one for a header and one for a container. How can I create them?
I can't find any utility in Xcode/Interface Builder to create WKWebview instances. I can create a WebView which is of type UIWebView, but I can't call WkWebView methods on it and I can't conversion it to a WKWebview.
回答1:
var item = WKWebView()
item.frame = CGRectMake(0, 0,
self.view.bounds.width, 200.)
self.view.addSubview(item)
item = WKWebView()
item.frame = CGRectMake(0, self.view.bounds.height-200.,
self.view.bounds.width, 200.)
self.view.addSubview(item)
This code add WKWebView
at the top and bottom of self.view
.
回答2:
var item = WKWebView()
item.frame = CGRectMake(0,0,self.view.bounds.width,self.view.bounds.height)
var path = NSBundle.mainBundle().pathForResource("header", ofType:".html")
var url = NSURL.fileURLWithPath(path!)
var request = NSURLRequest(URL:url!)
item.loadRequest(request) self.view.addSubview(item)
var item1 = WKWebView()
item1.frame = CGRectMake(0, 50, self.view.bounds.width, self.view.bounds.height)
var url1 = NSURL(string:"kinderas.com/")
var req = NSURLRequest(URL:url1)
item1.loadRequest(req)
self.view.addSubview(item1)
来源:https://stackoverflow.com/questions/27401276/how-to-create-two-wkwebview