1.创建一个进度条对象progressView,并初始化 注意:identifity的值一定要是estimatedProgress
- (UIProgressView *)progressView{
if (!_progressView) {
_progressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
_progressView.tintColor = DefaultBtnColor;
_progressView.trackTintColor = [UIColor groupTableViewBackgroundColor];
}
return _progressView;
}
2.监听wkWebView
[self.wkWebView addObserver:self forKeyPath:@"estimatedProgress" options:NSKeyValueObservingOptionNew context:nil];
3.实现监听事件
#pragma mark - kvo
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context{
if (object == self.wkWebView && [keyPath isEqualToString:@"es