SVProgressHUD的作用及用法

SVProgressHUD 是一个第三方的控件,是一个弹出提示层,用来提示网络加载、或提示对错,如下图所示:

 
 
那么,SVProgressHUD 都有什么特点呢?
 
1. 提示当前的状态,如:网络传输、提交中、操作成功或失败等;
 
2. 可设置提示的 pop layer 是否为 model,提示的时候是否允许用户做其他操作;
 
3. 可以设置背景色和自定义提示的内容;
 
4. 使用起来非常简洁,代码量非常少。
 
 
 
那么如何使用 SVProgressHUD 呢?
 
1.  官网下载代码,并放入到项目中;
 
2. 在使用到的项目里面,加入引用  #import "SVProgressHUD.h";
 
3. 在需要提示的地方,加入调用代码 ,如:    
[SVProgressHUD showWithStatus:@"加载中..." maskType:SVProgressHUDMaskTypeGradient];
 
4. 在需要隐藏的地方,加入隐藏当前提示的代码,如:“[SVProgressHUD dismiss];”。
 
 
SVProgressHUD 常用方法介绍:
 
1. + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType 调用 SVProgressHUD,并自定义 提示的内容 和 提示层的样式;
 
2. + (void)dismiss 关闭当前提示;
 
 
SVProgressHUDMaskType 介绍:
 
1. SVProgressHUDMaskTypeNone : 当提示显示的时间,用户仍然可以做其他操作,比如View 上面的输入等
 
2. SVProgressHUDMaskTypeClear : 用户不可以做其他操作
 
3. SVProgressHUDMaskTypeBlack : 用户不可以做其他操作,并且背景色是黑色
 
4. SVProgressHUDMaskTypeGradient : 用户不可以做其他操作,并且背景色是渐变的
 
 
SVProgressHUD 全部方法:
 
+ (void)show;
+ (void)showWithStatus:(NSString*)status;
+ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
 
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showSuccessWithStatus:(NSString *)string duration:(NSTimeInterval)duration;
+ (void)showErrorWithStatus:(NSString *)string;
+ (void)showErrorWithStatus:(NSString *)string duration:(NSTimeInterval)duration;
 
+ (void)setStatus:(NSString*)string; // change the HUD loading status while it's showing
 
+ (void)dismiss; // simply dismiss the HUD with a fade+scale out animation
+ (void)dismissWithSuccess:(NSString*)successString; // also displays the success icon image
+ (void)dismissWithSuccess:(NSString*)successString afterDelay:(NSTimeInterval)seconds;
+ (void)dismissWithError:(NSString*)errorString; // also displays the error icon image
+ (void)dismissWithError:(NSString*)errorString afterDelay:(NSTimeInterval)seconds;
 
+ (BOOL)isVisible;

下面是代码示例:

  1. #import "ViewController.h"  
  2. #import <SVProgressHUD/SVProgressHUD.h>  
  3.   
  4. @interface ViewController ()  
  5.   
  6. @end  
  7.   
  8. @implementation ViewController  
  9.   
  10. - (void)viewDidLoad  
  11. {  
  12.     [super viewDidLoad];  
  13. }  
  14.   
  15.   
  16. - (void)didReceiveMemoryWarning  
  17. {  
  18.     [super didReceiveMemoryWarning];  
  19. }  
  20.   
  21. - (IBAction)show:(id)sender {  
  22.   //  [SVProgressHUD show];  
  23.    //SVProgressHUDMaskType 设置显示的样式  
  24.    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];  
  25.    [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  26. }  
  27.   
  28. - (IBAction)showText:(id)sender {  
  29.     [SVProgressHUD showWithStatus:@"加载中,请稍后。。。"];  
  30.     [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  31. }  
  32.   
  33. - (IBAction)showprogress:(id)sender {  
  34.     [SVProgressHUD showProgress:0 status:@"加载中"];  
  35.     [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];  
  36. }  
  37.   
  38.   
  39. static float progressValue = 0.0f;  
  40. - (void)increateProgress  
  41. {  
  42.     progressValue += 0.1;  
  43.     [SVProgressHUD showProgress:progressValue status:@"加载中"];  
  44.     if (progressValue < 1) {  
  45.          [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];  
  46.     }else{  
  47.         [self performSelector:@selector(dismiss:) withObject:nil afterDelay:0.4];  
  48.     }  
  49.   
  50. }  
  51.   
  52. - (IBAction)dismiss:(id)sender {  
  53.     [SVProgressHUD dismiss];  
  54. }  
  55.   
  56. - (IBAction)showSuccess:(id)sender {  
  57.     [SVProgressHUD showSuccessWithStatus:@"success"];  
  58.     [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  59. }  
  60.   
  61. - (IBAction)showError:(id)sender {  
  62.     [SVProgressHUD showErrorWithStatus:@"error"];  
  63.     [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  64. }  
  65.   
  66.   
  67. @end  
复制代码
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值