Njkwebviewprogress--webview progress bar

Source: Internet
Author: User

Import Header File
#import "NJKWebViewProgressView.h"#import "NJKWebViewProgress.h"
Compliance Agreement
  <UIWebViewDelegate, NJKWebViewProgressDelegate>
Implementation code
@implementationviewcontroller{Iboutlet __WeakUIWebView *_webview; Njkwebviewprogressview *_webviewprogressview; Njkwebviewprogress *_webviewprogress;} - (void) viewdidload{[Super Viewdidload]; _webviewprogress = [[Njkwebviewprogress alloc] init]; _webview. Delegate = _webviewprogress; _webviewprogress. webviewproxydelegate =Self _webviewprogress. progressdelegate =SelfCGRect navbounds =Self. Navigationcontroller. Navigationbar. Bounds;CGRect Barframe =CGRectMake (0, Navbounds. Size. Height-2, Navbounds. Size. width,2); _webviewprogressview = [[Njkwebviewprogressview alloc] Initwithframe:barframe];_webviewprogressview. Autoresizingmask =Uiviewautoresizingflexiblewidth |Uiviewautoresizingflexibletopmargin; [_webviewprogressview setprogress:0 Animated:YES]; [Self Loadbaidu]; [Self.navigationcontroller.navigationbar addSubview:_ Webviewprogressview];} -(void) loadbidu{nsurlrequest *req = [[nsurlrequest alloc" Initwithurl:[nsurl urlwithstring:@" http://www.baidu.com/"]; [_webview loadrequest:req];}  #pragma mark-njkwebviewprogressdelegate-(void) Webviewprogress: (njkwebviewprogress *) webviewprogress updateprogress: (float) progress{ [_webviewprogressview setprogress:progress animated:yes]; self.title = [_webview Stringbyevaluatingjavascriptfromstring:@ "Document.title"];}      

Njkwebviewprogress is how to do, analysis is as follows:

    • Webviewdidstartload is the start of a request, all requests go through it, before loading the resource, can get a URL how many resources need to load, use _loadingcount++ way to count.
    • webviewdidfinishload, is the end of a request, each request ends _loadingcount--, and re-count progress
    • progress using _loadingcount/_maxloadcount the way to calculate
    • Every time webviewdidfinishload,Didfailloadwitherror requests are added to the Waitforcompletejs such as JS into the Web view, To detect if the Web page is loaded.
      • To get the progress of the logic and display the view of the progress of separate writing, with the agent to connect two classes, the structure is clear, the implementation will be more convenient

Njkwebviewprogress--webview progress bar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.