So I just updated to the new Xcode8
and Swift3
but now my web view does not work. Here is the code I used:
UIWebView.loadRequest(webVie
A dynamic webview class with loading :
class WebViewController : UIViewController, UIWebViewDelegate {
var url : String!
var webView : UIWebView!
var loadingView : UIActivityIndicatorView!
override func viewDidLoad() {
let x = Int(UIScreen.main.bounds.width / 2 - 25)
loadingView = UIActivityIndicatorView(frame : CGRect(x: x, y: 100, width: 50, height: 50))
loadingView.activityIndicatorViewStyle = .gray
webView = UIWebView(frame: UIScreen.main.bounds)
webView.delegate = self
view.addSubview(webView)
if let url = URL(string: url) {
let request = URLRequest(url: url)
webView.loadRequest(request)
}else{
self.navigationController?.popViewController(animated: true)
}
view.addSubview(loadingView)
loadingView.startAnimating()
}
func webViewDidFinishLoad(_ webView: UIWebView) {
loadingView.removeFromSuperview()
}
static func initController() -> WebViewController {
let vc = WebViewController()
return vc
}
}
///// use it
let webvc = WebViewController.initController()
webvc.url = "http://apple.com"
self.navigationController?.pushViewController(webvc, animated: true)