1

ViewController.m

- (void)viewDidLoad {
    self.webViewIpad.scalesPageToFit = YES;
    NSString *urlString = @"https://google.com";
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
   [self.webViewIpad loadRequest:urlRequest];
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    myProgressView.progress = 0;
    theBool = false;
    //0.01667 is roughly 1/60, so it will update at 60 FPS
    myTimer = [NSTimer scheduledTimerWithTimeInterval:0.01667 target:self selector:@selector(timerCallback) userInfo:nil repeats:YES];
}

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    theBool = true;`
}

- (void)timerCallback {
    if (theBool) {
        if (myProgressView.progress >= 1) {
            myProgressView.hidden = true;
            [myTimer invalidate];
        }
        else {
            myProgressView.progress += 0.1;
        }
    }
    else {
        myProgressView.progress += 0.05;
        if (myProgressView.progress >= 0.95) {
            myProgressView.progress = 0.95;
        }
    }
}

I had this in my code. What should I do to connect my webview in my progress bar? Can anyone help me?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Adrian Salim
  • 53
  • 1
  • 5
  • 1
    If you want the progress view to have an accurate progress indication then you should be using WKWebView and get the progress from `estimatedProgress` – Mistah_Sheep Nov 06 '16 at 19:34
  • @Mistah_Sheep can you help me with example code(simple code)? i'm newbie in here – Adrian Salim Nov 07 '16 at 06:30
  • @Mistah_Sheep in case he is supporting old iOS versions he can't use WKWebView. There is any solution for doing that in UIWebView? – VitorMM Dec 08 '16 at 12:06
  • I guess this the best you can do with UIWebView: http://stackoverflow.com/a/8248509/4370893 – VitorMM Dec 08 '16 at 12:12

0 Answers0