How to hide the Finish button and search bar in SafariViewController

I use SafariViewController to display a web page, and instead of the done button, by default I exit my NavigationController application to save my nav stack and back arrow. However, I need to hide the Finish button by default and the search bar on the SafariViewController . Is it possible? See my code and screenshot below ...

 let svc = SFSafariViewController(URL: pinterestSafariURL) navigationController?.pushViewController(svc, animated: true) 

enter image description here

note: a link to this question, but the answer is a hack, while I was looking for a solution using the SafariViewController API: SFSafariViewController: Hide the navigation bar

+7
source share
2 answers

In the Apple documentation on the SFSafariViewController , there seems to be no public way to hide the Finish button or URL bar. Apple suggests using WKWebView if you need a browser user interface.

There's an AppCoda WKWebView tutorial that shows you how to create a ViewController with a built-in WKWebView . Hope this helps!

+6
source

Get ready for ugliness and fragility:

 extension MyViewController: SFSafariViewControllerDelegate { func safariViewController(_ controller: SFSafariViewController, didCompleteInitialLoad didLoadSuccessfully: Bool) { let f = CGRect(origin: CGPoint(x: 0, y: 20), size: CGSize(width: 90, height: 44)) let uglyView = UIView(frame: f) uglyView.backgroundColor = svc.view.backgroundColor controller.view.addSubview(uglyView) } } 

Obviously, the origin needs to be fixed for the iPhone X so that it works more or less.

0
source

Source: https://habr.com/ru/post/1247090/


All Articles