首页 > 代码库 > iOS UIWebView 加载进度条的使用

iOS UIWebView 加载进度条的使用

1/拖到自己的??

2/ 这是 原文介绍的步骤。。但是再加入后,背景回短暂的绿色,我自己是想不要那个闪一下的状态

#import "InspectionReportViewController.h"

#import "NJKWebViewProgressView.h"
#import "NJKWebViewProgress.h"


@interface InspectionReportViewController ()<UIWebViewDelegate,NJKWebViewProgressDelegate>
{
    UIWebView *webview;

    NJKWebViewProgressView *_progressView;
    NJKWebViewProgress *_progressProxy;
    
}
@end

@implementation InspectionReportViewController



-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
  //页面结束 去掉 视图
    [_progressView removeFromSuperview];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

   
    webview = [[UIWebView alloc] initWithFrame:self.view.bounds];
    webview.backgroundColor = [UIColor blackColor];
    
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://www.baidu.com]]]];

    webview.scalesPageToFit = YES;

    webview.scrollView.scrollEnabled = NO;

    [self.view addSubview:webview];
    
    
    _progressProxy = [[NJKWebViewProgress alloc] init];
    webview.delegate = _progressProxy;
    _progressProxy.webViewProxyDelegate = self;
    _progressProxy.progressDelegate = self;
   
    CGFloat progressBarHeight = 2.f;
    CGRect navigationBarBounds = 
self.navigationController.navigationBar.bounds;
    CGRect barFrame = CGRectMake(0, navigationBarBounds.size.height - progressBarHeight-IPHONEHIGHT(40), navigationBarBounds.size.width, progressBarHeight);

    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;
    
    [webview addSubview:_progressView];

  
}

//代理方法
#pragma mark - NJKWebViewProgressDelegate
-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
    
}

 

3/ 。在 下面这个问价中??下面??

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #d12f1b } span.s1 { }</style>

NJKWebViewProgressView.m 

 

//在这个方法中修改一下
-(void)configureViews{

 UIColor *tintColor = [UIColor ClearColor]; // iOS7 Safari bar color

}


//第二时这个方法中的改变 。在第二行

- (void)setProgress:(float)progress animated:(BOOL)animated
{
    BOOL isGrowing = progress > 0.0;


 //下面这个方法是加进去的   
_progressBarView.backgroundColor = [UIColor colorWithRed:22.f / 255.f green:126.f / 255.f blue:251.f / 255.f alpha:1.0]; ;
    

 

iOS UIWebView 加载进度条的使用