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
#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
相关文章推荐
- IOS 三维图像处理(九)--CATransform3D
- android ContentResolver的使用(获取和修改联系人信息demo)
- Android apk动态加载机制的研究
- Android Studio常用插件
- iOS 字体转换
- 介绍call,callee,caller,apply的区别与应用
- web.xml:<filter-mapping>里的dispatcher:404错误
- swift协议代理的使用以及解决循环引用问题
- iOS开发学习之 - 正则表达式在IOS中的应用
- ios学习之plist文件的读写以及存储位置的探究
- DefaultAnnotationHandlerMapping 和 AnnotationMethodHandlerAdapter 的使用已经过时!
- Android Studio debug使用release的签名
- UIWebView页面加载不出来的解决方案
- iOS动画开发之五——炫酷的粒子效果
- JavaScript Object.prototype.toString 解析过程
- Android debug.keystore的密码
- Objective-C的hook方案(一): Method Swizzling
- Android 获取系统时间的时间戳
- iOS中的加密:MD5
- iOS 中copy的简单理解