SVProgressHUD使用详解

一、简要说明

  • SVProgressHUD用来显示正在进行的任务的进展情况,用于显示任务加载时的动画,有很多种样式的提示框,非常轻便,容易使用,可用于iOS和tvOS。

SVProgressHUD下载地址

二、用法

  • 在网络请求、下拉刷新、无限滚动、发送消息时都可以使用SVProgressHUD来展示任务进展情况。

[SVProgressHUD show];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    // time-consuming task
    dispatch_async(dispatch_get_main_queue(), ^{
        [SVProgressHUD dismiss];
    });
});

三、集成方式

1、通过Cocoapods

  •  将 pod 'SVProgressHUD' 添加到Podfile文件中,然后在终端执行命令pod install
  • 在要使用的类中引入头文件即可使用SVProgressHUD

#import <SVProgressHUD.h>

2、手动

  • 拖拽 SVProgressHUD/SVProgressHUD文件夹到你的项目,把  SVProgressHUD.bundle 添加进 Targets->Build Phases->Copy Bundle Resources,添加 QuartzCore framework 到你的项目。
  • 在要使用的类中引入头文件即可使用SVProgressHUD

#import "SVProgressHUD.h"

四、主要功能

1.指示任务的状态

[SVProgressHUD showWithStatus:@"加载中,请稍后。。。"];

2.指示任务的进度

 progressValue += 0.1;  
 [SVProgressHUD showProgress:progressValue status:@"加载中"]; 

3.HUB隐藏

[SVProgressHUD dismiss];
或者[SVProgressHUD dismissWithDelay:1.0];

4.显示一个提示消息

[SVProgressHUD showErrorWithStatus:@"当前网络不稳定,请稍后重试"];

5.自定义

[SVProgressHUD setDefaultStyle:SVProgressHUDStyleCustom];
[SVProgressHUD setBackgroundColor:[UIColor blackColor]];
[SVProgressHUD setForegroundColor:[UIColor whiteColor]];

6.通知

6.1 SVProgressHUD通过NSNotificationCenter 注册4份通知,以响应正在显示/消失:
  • SVProgressHUDWillAppearNotification 提示框即将出现
  • SVProgressHUDDidAppearNotification 提示框已经出现
  • SVProgressHUDWillDisappearNotification 提示框即将消失  
  • SVProgressHUDDidDisappearNotification 提示框已经消失
  • 每个通知传递一个userInfo字典,字典中包含HUD的状态字符串(如果有的话),可通过SVProgressHUDStatusUserInfoKey作为键来获取。
6.2  SVProgressHUD还发送通知:
  • SVProgressHUDDidReceiveTouchEventNotification当用户触摸整体屏幕上
  • SVProgressHUDDidTouchDownInsideNotification当用户直接在HUD接触。

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleNotification:)
                                                 name:SVProgressHUDWillAppearNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleNotification:)
                                                 name:SVProgressHUDDidAppearNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleNotification:)
                                                 name:SVProgressHUDWillDisappearNotification
                                               object:nil];
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(handleNotification:)
                                                 name:SVProgressHUDDidDisappearNotification
                                               object:nil];
}

五、当前版本

`2.0-beta8`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值