之前做等待跳转都是用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. [LeetCode]题解(python):072-Edit Distance

    题目来源: https://leetcode.com/problems/edit-distance/ 题意分析: word1最少通过多少步可以变成word2.word1只能进行一下的操作.a)插入一个 ...

  2. eclipse设置web项目发布到tomcat根目录下

    如果已经将项目绑定到服务器了,那就先删除服务器. 重新添加项目进服务器,双击 修改下面Server Locations到tomcat目录下 顺带可以修改下右上角的超时设置 再点击下方 这样就可以了.

  3. 基于FPGA的key button等开关消抖,按键消抖电路设计

    最近要用上一个key消抖的功能.于是找到了之前写的并放入博客的程序,发现居然全部有问题.http://www.cnblogs.com/sepeng/p/3477215.html —— 有问题,包括很多 ...

  4. 25_Downloading An Image

    一个App,从网上下载一张图片(给出图片地址),重新命名,然后保存到手机中,再从手机中取出显示在屏幕上. 难度不大,就是找图片很蛋疼,百度搜索出来的过一会儿会失效,Google搜索出来的有些需要FQ, ...

  5. QBoxLayout::setSizeConstraint可以固定窗口的大小,且根据内部控件所占用的位置自动调节大小

    setSizeConstraint(QLayout::SetFixedSize)的功能是保持整个对话框的尺寸保持相对固定.也就是说让布局管理器来调整对话框的大小.举个例子吧:一个上下可扩展对话框,基本 ...

  6. TreeView控件例子

    XmL文件代码: <?xml version="1.0" encoding="utf-8" ?> <Area> <Province ...

  7. 网页压缩gzip的问题及说明教程

    关于网页压缩gzip的问题及说明教程 最近比较多人反应gzip的问题 在wdcp的后台里已经有gzip功能的选项,也就是说,只要在这里开启了,就已支持 但从最近的问题中发现,基本上都是使用一些在线检测 ...

  8. the convertion between string and BlobColumn

    It's hard to find some samples about the convertion between string and BlobColumn.AddBlobData. It's ...

  9. Enze Third day(c#中选择结构【if...else】)

    哈喽,又到了我总结课堂知识的时间了.今天在云和学院学的是C#中的“选择结构”下的If语句.下面就来总结一下今天所学的吧. 理论:If语句是最常用的选择结构语句.它主要根据所给定的条件(常由关系表达式和 ...

  10. ACE6.2.0文件/目录操作

    文件读取.#include "ace/FILE_Connector.h"#include "ace/FILE_IO.h"void fileRW(){ACE_FI ...