How to Create Two WkWebView

旧城冷巷雨未停 提交于 2021-02-08 12:14:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!