方法
SVProgressHUD所以的方法都是類方法,并且對象是通過單例創建。由于方法都是通過類名調用,簡單明了。
基本方法
+ (void)show; 顯示:狀態是一個迅速轉動的圈
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType; 顯示并且帶著一個狀態
+ (void)showWithStatus:(NSString*)status; 顯示并且帶著文字
+ (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
+ (void)showProgress:(float)progress; //顯示進度:狀態是一個進度圈
+ (void)showProgress:(float)progress maskType:(SVProgressHUDMaskType)maskType;
+ (void)showProgress:(float)progress status:(NSString*)status;
+ (void)showProgress:(float)progress status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
+ (void)setStatus:(NSString*)string; // 改變正顯示著的HUD的文字
// stops the activity indicator, shows a glyph + status, and dismisses HUD a little bit later
+ (void)showInfoWithStatus:(NSString *)string; //顯示消息信息,其實就是中心圖片更換了
+ (void)showInfoWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
+ (void)showSuccessWithStatus:(NSString*)string; //顯示成功消息
+ (void)showSuccessWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
+ (void)showErrorWithStatus:(NSString *)string; //顯示錯誤消息
+ (void)showErrorWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
// use 28x28 white pngs
+ (void)showImage:(UIImage*)image status:(NSString*)status; //顯示自己設置的圖片,圖片大小事28 * 28 px
+ (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
+ (void)setOffsetFromCenter:(UIOffset)offset; //距離中心點的偏移量
+ (void)resetOffsetFromCenter; //返回中心點
+ (void)popActivity; // 消除一個HUD,根據其實現方法如果前面有執行了好幾次show方法,如果給定的progress == 0 或者 pregress < 0那樣就會讓使一個參數+1,執行這個方法會使那個參數-1,如果參數==0時 執行dismiss方法。
+ (void)dismiss; 消失
+ (BOOL)isVisible; 是否正在顯示
關于HUD的屬性配置
+ (void)setBackgroundColor:(UIColor*)color; //背景顏色 // default is [UIColor whiteColor]
+ (void)setForegroundColor:(UIColor*)color; //progress 和 label顏色 // default is [UIColor blackColor]
+ (void)setRingThickness:(CGFloat)width; //progress 寬度 // default is 4 pt
+ (void)setFont:(UIFont*)font; //字體 // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline]
+ (void)setInfoImage:(UIImage*)image; //消息的圖片 // default is the bundled info image provided by Freepik
+ (void)setSuccessImage:(UIImage*)image; //成功時的圖片 // default is the bundled success image provided by Freepik
+ (void)setErrorImage:(UIImage*)image; //失敗時的圖片 // default is the bundled error image provided by Freepik
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; //當HUD顯示時,用戶是否可以點擊其他控件// default is SVProgressHUDMaskTypeNone
SVProgressHUDMaskTypeNone = 1, // 允許用戶進行其他用戶操作
SVProgressHUDMaskTypeClear, // 不允許用戶進行其他用戶操作
SVProgressHUDMaskTypeBlack, // 不允許用戶進行其他用戶操作,并且背景是黑色的
SVProgressHUDMaskTypeGradient // 允許用戶進行其他用戶操作,并且背景是漸變的黑色
+ (void)setViewForExtension:(UIView*)view; //可以延展一個圖片必須設置#define SV_APP_EXTENSIONS
關于HUD的通知
extern NSString * const SVProgressHUDDidReceiveTouchEventNotification; 在HUD外點擊
extern NSString * const SVProgressHUDDidTouchDownInsideNotification; 在HUD中點擊
extern NSString * const SVProgressHUDWillDisappearNotification; 將要顯示
extern NSString * const SVProgressHUDDidDisappearNotification; 已經顯示
extern NSString * const SVProgressHUDWillAppearNotification; 將要消失
extern NSString * const SVProgressHUDDidAppearNotification; 已經消失
extern NSString * const SVProgressHUDStatusUserInfoKey; HUD的狀態
在通知中userInfo字典中存儲了HUD的狀態,其key為SVProgressHUDStatusUserInfoKey
MBProgressHUD的基本使用
/**
* 類方法
*/
/*
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
@weakify(hud)
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
@strongify(hud)
[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
});
*/
/**
* 實例方法
*/
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
//顯示hud的模式
hud.mode = MBProgressHUDModeDeterminate;
//背景顏色
hud.color = [UIColor redColor];
//主標題
hud.labelText = @"主標題";
//副標題
hud.detailsLabelText = @"副標題";
//顯示、隱藏時的動畫樣式
hud.animationType = MBProgressHUDAnimationZoomIn;
//當mode的屬性是跟進度相關時,就可以設置progress的值,實現實時進度的顯示
hud.progress = 0.8;
// HUD的相對于父視圖 x 的偏移,默認居中
// hud.xOffset = 50;
// hud.yOffset = 50;
//是否顯示蒙板
hud.dimBackground = YES;
//HUD內部視圖相對于HUD的內邊距
hud.margin = 50;
//HUD的圓角半徑
hud.cornerRadius = 20;
//最小的顯示時間
hud.minShowTime = 3.0;
// HUD的最小尺寸
hud.minSize = CGSizeMake(300, 300);
// 代理中只有一個方法,即獲得HUD隱藏后的時刻
// hud.delegate = self;
[self.view addSubview:hud];
[hud showAnimated:YES whileExecutingBlock:^{
//hud執行期間
NSLog(@"執行期間");
} onQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) completionBlock:^{
//hud執行完畢
NSLog(@"執行完畢");
}];
}