Reputation: 1443
I want to make Back button from mySubView. I have payment ViewController with button, this button make view.addSubview(WkWebView). So i can open WkWebView but i have no possibility to lose it.
My code:
self.automaticallyAdjustsScrollViewInsets = false
self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
self.wkWebView.frame = CGRect.init(x: 0, y: 0, width: self.wkWebView.frame.size.width, height: self.wkWebView.frame.size.height)
self.view.addSubview(wkWebView)
loadUrl()
func loadUrl(){
let webConfiguration = WKWebViewConfiguration()
webConfiguration.allowsInlineMediaPlayback = true
let myURL = URL(string: "https://ecg.test.upc.ua/go/enter")
var myRequest = URLRequest(url: myURL!)
myRequest.httpMethod = "POST"
wkWebView.load(myRequest)
}
Upvotes: 0
Views: 55
Reputation: 100533
You can try this
let back = UIButton(type: .system)
back.frame = CGRect(x: 10, y: 20, width: 100, height: 50)
back.setTitle("Back", for: .normal)
back.sizeToFit()
back.addTarget(self, action: #selector(self.back), for: .touchUpInside)
wkWebView.addSubview(back)
//
@objc func back() {
wkWebView.removeFromSuperview()
}
//
also give a frame to the wkWebView
in a relation to the superView , and don't set self.wkWebView.translatesAutoresizingMaskIntoConstraints = false
as it's when you add constraints
self.wkWebView.frame = self.view.framw
Upvotes: 1