SVProgressHUD控制元件使用 進度條
阿新 • • 發佈:2019-02-08
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:
1 2 3 |
+ (void)showSuccessWithStatus:(NSString*)string; + (void)showErrorWithStatus:(NSString *)string; + (void)showImage:(UIImage*)image status:(NSString*)string;// use 28x28 white pngs |
- #import "ViewController.h"
- #import <SVProgressHUD/SVProgressHUD.h>
-
@interface
- @end
- @implementation ViewController
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- - (IBAction)show:(id)sender {
- // [SVProgressHUD show];
- //SVProgressHUDMaskType 設定顯示的樣式
- [SVProgressHUD showWithMaskType:SVProgressHUDMaskTypeBlack];
- [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];
- }
- - (IBAction)showText:(id)sender {
- [SVProgressHUD showWithStatus:@"載入中,請稍後。。。"];
- [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];
- }
- - (IBAction)showprogress:(id)sender {
- [SVProgressHUD showProgress:0 status:@"載入中"];
- [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];
- }
- static float progressValue = 0.0f;
- - (void)increateProgress
- {
- progressValue += 0.1;
- [SVProgressHUD showProgress:progressValue status:@"載入中"];
- if (progressValue < 1) {
- [self performSelector:@selector(increateProgress) withObject:nil afterDelay:0.3];
- }else{
- [self performSelector:@selector(dismiss:) withObject:nil afterDelay:0.4];
- }
- }
- - (IBAction)dismiss:(id)sender {
- [SVProgressHUD dismiss];
- }
- - (IBAction)showSuccess:(id)sender {
- [SVProgressHUD showSuccessWithStatus:@"success"];
- [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];
- }
- - (IBAction)showError:(id)sender {
- [SVProgressHUD showErrorWithStatus:@"error"];
- [self performSelector:@selector(dismiss:) withObject:nil afterDelay:3];
- }
- @end