UIWebView with Progress Bar

后端 未结 9 1396
攒了一身酷
攒了一身酷 2020-12-08 00:47

Hi I\'m new to programming and I\'m trying to make my first app for iPhones on Xcode. My app contains of a button which opens a UIWebView when pressed and loads up a homepag

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 01:34

    If anyone wants to do it in swift 3, I spent a few days trying to figure it out and finally did.

    Here is the code :)

    override func viewDidLoad() {
        super.viewDidLoad()
    
        let url = NSURL(string: "http://google.com")
        let request = NSURLRequest(url: url as! URL)
        webView.loadRequest(request as URLRequest)
        webView.delegate=self
    
    }
    
    func webViewDidStartLoad(_ webView: UIWebView) {
    
        self.progressView.setProgress(0.1, animated: false)
    }
    
    
    func webViewDidFinishLoad(_ webView: UIWebView) {
    
        self.progressView.setProgress(1.0, animated: true)
    }
    
    func webView(_ webView: UIWebView, didFailLoadWithError error: Error) {
    
        self.progressView.setProgress(1.0, animated: true)
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

提交回复
热议问题