1. 程式人生 > >SVProgressHUD控制元件使用 進度條

SVProgressHUD控制元件使用 進度條

GitHub:https://github.com/samvermette/SVProgressHUD
SVProgressHUD和MBProgressHUD效果差不多,不過不需要使用協議,同時也不需要宣告例項。
直接通過類方法進行呼叫即可:

1 [SVProgressHUD method]

可以使用以下方法來顯示狀態:

1
2
3
4
+ (void)show;
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType;
+ (void)showWithStatus:(NSString*)string;
+ (void)showWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;

如果需要明確的進度,則使用以下方法:

1
2
3
+ (void)showProgress:(CGFloat)progress;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status;
+ (void)showProgress:(CGFloat)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;

通過dismiss方法來隱藏提示:

1 + (void)dismiss;

另外提供了以下方法用於顯示狀態,並在1秒後自動隱藏提示(使用的圖示來源於Glyphish:

http://www.glyphish.com/):

1
2
3
+ (void)showSuccessWithStatus:(NSString*)string;
+ (void)showErrorWithStatus:(NSString *)string;
+ (void)showImage:(UIImage*)image status:(NSString*)string;// use 28x28 white pngs
Java程式碼  收藏程式碼
  1. #import "ViewController.h"  
  2. #import <SVProgressHUD/SVProgressHUD.h>  
  3. @interface
     ViewController ()  
  4. @end  
  5. @implementation ViewController  
  6. - (void)viewDidLoad  
  7. {  
  8.     [super viewDidLoad];  
  9. }  
  10. - (void)didReceiveMemoryWarning  
  11. {  
  12.     [super didReceiveMemoryWarning];  
  13. }  
  14. - (IBAction)show:(id)sender {  
  15.   //  [SVProgressHUD show];  
  16.    //SVProgressHUDMaskType 設定顯示的樣式  
  17.    [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];  
  18.    [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  19. }  
  20. - (IBAction)showText:(id)sender {  
  21.     [SVProgressHUD showWithStatus:@"載入中,請稍後。。。"];  
  22.     [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  23. }  
  24. - (IBAction)showprogress:(id)sender {  
  25.     [SVProgressHUD showProgress:0 status:@"載入中"];  
  26.     [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];  
  27. }  
  28. static float progressValue = 0.0f;  
  29. - (void)increateProgress  
  30. {  
  31.     progressValue += 0.1;  
  32.     [SVProgressHUD showProgress:progressValue status:@"載入中"];  
  33.     if (progressValue < 1) {  
  34.          [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];  
  35.     }else{  
  36.         [self performSelector:@selector(dismiss:) withObject:nil afterDelay:0.4];  
  37.     }  
  38. }  
  39. - (IBAction)dismiss:(id)sender {  
  40.     [SVProgressHUD dismiss];  
  41. }  
  42. - (IBAction)showSuccess:(id)sender {  
  43.     [SVProgressHUD showSuccessWithStatus:@"success"];  
  44.     [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  45. }  
  46. - (IBAction)showError:(id)sender {  
  47.     [SVProgressHUD showErrorWithStatus:@"error"];  
  48.     [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];  
  49. }  
  50. @end