之前做等待跳转都是用UIActivityIndicatorView ,后来做webView 加载页面的时候,发现了一个特别好用又超级炫酷的加载提示NJKWebViewProgress,作者巧妙的通过计算加载请求的个数,用百分比展示进度,并且集成了加载页面的title,效果惊艳业界。今将使用步骤记录,方便日后查询,也希望能给朋友们带来一点帮助。

1、首先将炫酷的NJKWebViewProgress 拖到工程,赶紧"占为已有"

2、在加载页面铺以下代码,由于对NJKWebViewProgress的理解都是个人的,就不一一注释了,以免不到之处误导查询者。

@interface ViewController ()<UIWebViewDelegate,NJKWebViewProgressDelegate>{

UIWebView *_webView;
    NJKWebViewProgressView *_progressView;
    NJKWebViewProgress *_progressProxy;
    NSURLRequest *req;
    
    BOOL cameraBool;
    UIImagePickerController *cameraPick;
    
    
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0,WIDTH, HEIGHT)];
    _webView.scalesPageToFit = YES;
    [self.view addSubview:_webView];
    
    
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(replyEvent)];
    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh target:self action:@selector(refreshEvent)];
    
    self.navigationItem.leftBarButtonItem = item;
    self.navigationItem.rightBarButtonItem = item1;

_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, navigationBarBounds.size.width, progressBarHeight);
    _progressView = [[NJKWebViewProgressView alloc] initWithFrame:barFrame];
    _progressView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin;

[self jump];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self.navigationController.navigationBar addSubview:_progressView];
}

-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [_progressView removeFromSuperview];
}

-(void)replyEvent{
    
    [_webView goBack];
}

-(void)refreshEvent{
    [_webView reload];
}

-(void)jump{
    
    if(self.k == 1){
        req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://www.baidu.com/index.php?tn=monline_3_dg"]];}
//    }else if (self.k == 2){
//    req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.cnblogs.com/wangyang1213/"]];
//    }else if(self.k == 3){
//       req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.163.com/"]];
//    }
    else{
    req = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://cc.yztcai.com/h5.php"]];
    }
    
    [_webView loadRequest:req];
}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error{
    
    if(error != NULL){
        UIAlertController *alertController1 = [UIAlertController alertControllerWithTitle:@"提示" message:@"网络连接异常" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *sureAction1 = [UIAlertAction actionWithTitle:@"确定" style:0 handler:nil];
        UIAlertAction *cancelAction1 = [UIAlertAction actionWithTitle:@"取消" style:0 handler:nil];
        [alertController1 addAction:sureAction1];
        [alertController1 addAction:cancelAction1];
        [self presentViewController:alertController1 animated:YES completion:nil];
    }
}

-(void)webViewProgress:(NJKWebViewProgress *)webViewProgress updateProgress:(float)progress
{
    [_progressView setProgress:progress animated:YES];
    self.title = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
}

至此便集成了NJKWebViewProgress。拖到工程试试。

iOS UIWebView 之 UIProgressView的更多相关文章

  1. ios UIWebView截获html并修改便签内容(转载)

    ios UIWebView截获html并修改便签内容 博客分类: iphone开发iphone开发phoneGap uiwebviewstringByEvaluatingJavaScriptFromS ...

  2. IOS UIWebView截获html并修改便签内容,宽度自适应

    需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果:  方法:通过js截获UIWebView中的html,然后修改html标签内容:  实例代码:  服 ...

  3. ios UIWebView截获html并修改便签内容

    需求:混合应用UIWebView打开html后,UIWebView有左右滚动条,要去掉左右滚动效果: 方法:通过js截获UIWebView中的html,然后修改html标签内容: 实例代码: 服务器端 ...

  4. iOS UIWebView 获取内容实际高度,关闭滚动效果

    本文转载至 http://my.oschina.net/Khiyuan/blog/341535   iOS UIWebView 获取内容实际高度,关闭滚动效果 近期做东西,将 UIWebView 嵌套 ...

  5. iOS UIWebView获取403/404

    问题描述 与WindowsPhone不同,iOS UIWebView并不认为403/404这种情况下页面访问是失败的,这也情有可原,但有时候,我们需要对WebView所遇到的403/404进行处理. ...

  6. iOS UIWebView与JavaScript的交互 相关资料

    UIWebView自适应宽度 iOS UIWebView中javascript与Objective-C交互.获取摄像头 iOS中JavaScript和OC交互 iOS与js交互,获取webview完整 ...

  7. ios UIWebView自定义Alert风格的弹框

    之前开发过一个App,因为公司之前写好了网页版的内容和安卓版本的App,我进去后老板要求我ios直接用网页的内容,而不需要自己再搭建框架.我一听,偷笑了,这不就是一个UIWebView吗?简单! 但是 ...

  8. iOS --- UIWebView的加载本地数据的三种方式

    UIWebView是IOS内置的浏览器,可以浏览网页,打开文档  html/htm  pdf   docx  txt等格式的文件.  safari浏览器就是通过UIWebView做的. 服务器将MIM ...

  9. iOS UIWebView中javascript与Objective-C交互、获取摄像头

    UIWebView是iOS开发中常用的一个视图控件,多数情况下,它被用来显示HTML格式的内容. 支持的文档格式 除了HTML以外,UIWebView还支持iWork, Office等文档格式: Ex ...

随机推荐

  1. eclipse:Tomcat设置jvm,解决java.lang.OutOfMemoryError: Java heap space 堆内存溢出

    eclipse 有启动参数里设置jvm大小,因为eclipse运行时自己也需要jvm,所以eclipse.ini里设置的jvm大小不是具体某个程序运行时所用jvm的大小,这和具体程序运行的jvm大小无 ...

  2. eclipse手动添加源码

    在开发过程中,有的时候需要我们自已手动去添加一些源码文件,但是由于我们可能在eclipse中安装了jad反编译插件,我们再用“Ctrl + 鼠标左键”的话,会打开已经反编译好的class文件,而不是带 ...

  3. 不小心中了machook病毒

    此文运用的是优雅的Markdown而书 前段回家过年的日子,我心爱的小air在运行时不停的弹出"machook停止运行"的提醒,上网google一下不看不要紧,才得知是mac上的一 ...

  4. 论left-pad的实现

    这两天微博上看到左耳朵耗子吐槽了一下node社区的left-pad的代码,原po链接 我也思考了一下 怎么用实现一个left-pad比较合适,上图代码确实比较搓 leftpad功能,就是字符串前面拼指 ...

  5. Oracle笔记(十三) 视图、同义词、索引

    一.视图 在之前所学习过的所有的SQL语法之中,查询操作是最麻烦的,如果程序开发人员将大量的精力都浪费在查询的编写上,则肯定影响代码的工作进度,所以 一个好的数据库设计人员,除了根据业务的操作设计出数 ...

  6. RFID电子标签制造封装工艺和可靠性研究

    一.目的和意义 电子标签已经成为RFID工业的主要焦点 实现低成本.大批量.高可靠性地制造电子标签是推广RFID产品应用的关键技术之一 针对RFID标签制造中核心的封装工艺开展研究,以各向异性导 ...

  7. Protel99se教程五:protel99se的自动布线

    在上一节课的protel99se教程中,我们给大家演示的是,如何快速的将SCH原理PCB,也就是将元件转到PCB中,在这一节课,我们主要给大家讲解的是何在protel99se快速布线,我们在这节课当中 ...

  8. Protel99se轻松入门:一些高级设置和常用技巧

    给PCB补泪滴的具体操作 这里我们可以知道给PCB做覆铜是多么的简单 在PCB中如何找到我们要找的封装 在PCB中如何打印出中空的焊盘(这个功能对于热转印制板比较有用) 如何在PCB文件中加上漂亮的汉 ...

  9. UITextField align left margin

    如果我们想让我们的UITextField输入的字体偏移几个像素,我们常常用空格来代替,有时候我们不想用空格的话怎么办? #import <UIKit/UIKit.h> @interface ...

  10. squee_spoon and his Cube VI(贪心,找不含一组字符串的最大长度+kmp)

    1818: squee_spoon and his Cube VI Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 77  Solved: 22Subm ...