<h6 style="margin: 0px; font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif; line-height: 1.8; color: rgb(47, 47, 47); text-rendering: optimizelegibility;"><pre name="code" class="objc"><span style="font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;"><span style="font-size:12px;">导入头文件</span></span>
<span style="font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;"><span style="font-size:12px;">#import "NJKWebViewProgressView.h"</span></span>
<span style="font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;"><span style="font-size:12px;">#import "NJKWebViewProgress.h"</span></span>
<span style="font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;"><span style="font-size:12px;">遵守协议</span></span>
<span style="font-family: 'lucida grande', 'lucida sans unicode', lucida, helvetica, 'Hiragino Sans GB', 'Microsoft YaHei', 'WenQuanYi Micro Hei', sans-serif;"><span style="font-size:12px;"><UIWebViewDelegate, NJKWebViewProgressDelegate></span></span>
@implementation ViewController
{
IBOutlet __weak UIWebView *_webView;
NJKWebViewProgressView *_webViewProgressView;
NJKWebViewProgress *_webViewProgress;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_webViewProgress = [[NJKWebViewProgress alloc] init];
_webView.delegate = _webViewProgress;
_webViewProgress.webViewProxyDelegate = self;
_webViewProgress.progressDelegate = self;
CGRect 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"];
}