您的位置:首页 > 移动开发

UIWebView第三方进度条NJKWebViewProgress

2016-04-07 10:05 405 查看
WebView自定义进度条NJKWebViewProgress

#import "ViewController.h"

#import "NJKWebViewProgressView.h"

@implementation ViewController

{

    IBOutlet __weakUIWebView *_webView;

    NJKWebViewProgressView *_progressView;

    NJKWebViewProgress *_progressProxy;

}

- (void)viewDidLoad

{

    [superviewDidLoad];

    _progressProxy = [[NJKWebViewProgressalloc]
init];

    _webView.delegate =_progressProxy;

    _progressProxy.webViewProxyDelegate =self;

    _progressProxy.progressDelegate =self;

    _webView.scalesPageToFit =YES;//自动对页面进行缩放以适应屏幕

    CGFloat progressBarHeight =
2.f;

    CGRect navigationBarBounds =self.navigationController.navigationBar.bounds;

    CGRect barFrame =
CGRectMake(0, navigationBarBounds.size.height - progressBarHeight, navigationBarBounds.size.width,
progressBarHeight);

    _progressView = [[NJKWebViewProgressViewalloc]
initWithFrame:barFrame];

    _progressView.autoresizingMask =UIViewAutoresizingFlexibleWidth
| UIViewAutoresizingFlexibleTopMargin;

    [selfloadUrl:@"http://www.baidu.com"];

}

- (void)webViewDidStartLoad:(UIWebView *)webView

{

    // starting the load, show the activity indicator in the status bar

    [UIApplicationsharedApplication].networkActivityIndicatorVisible
=YES;

}

- (void)webViewDidFinishLoad:(UIWebView *)webView

{

    // finished loading, hide the activity indicator in the status bar

    [UIApplicationsharedApplication].networkActivityIndicatorVisible
=NO;

}

- (void)viewWillAppear:(BOOL)animated

{

    [super viewWillAppear:animated];

    [self.navigationController.navigationBaraddSubview:_progressView];

}

-(void)viewWillDisapp
c58c
ear:(BOOL)animated

{

    [super viewWillDisappear:animated];

    // Remove progress view

    // because UINavigationBar is shared with other ViewControllers

    [_progressViewremoveFromSuperview];

}

- (IBAction)searchButtonPushed:(id)sender

{

    [_webView goBack];

}

- (IBAction)reloadButtonPushed:(id)sender

{

    [_webView reload];

}

-(void)loadUrl:(NSString *)url

{

    NSURLRequest *req = [[NSURLRequestalloc]
initWithURL:[NSURLURLWithString:url]];

    [_webView loadRequest:req];

}

#pragma mark - NJKWebViewProgressDelegate

-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress

{

    [_progressView
setProgress:progress animated:YES];

    self.title = [_webViewstringByEvaluatingJavaScriptFromString:@"document.title"];

}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: