我可以使用下面的代码以编程方式将 WKWebView 添加到子视图。如何将 WKWebView 添加到通过 Interface Builder 添加的视图 containerView2?
import UIKit
import WebKit
class ViewController: UIViewController {
@IBOutlet var containerView : UIView?
@IBOutlet weak var containerView2: UIView!
var webView: WKWebView?
override func loadView() {
super.loadView()
self.webView = WKWebView()
self.webView?.frame = CGRectMake(50, 50, 200, 200)
self.webView?.sizeToFit()
self.containerView = self.webView!
//how can I set a View (containerView2) added by Interface Builder = to self.webView!
self.view.addSubview(self.containerView!)
}
override func viewDidLoad() {
super.viewDidLoad()
var url = NSURL(string:"http://www.google.com")
var req = NSURLRequest(URL:url)
self.webView!.loadRequest(req)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}