第三方架構中關于HUD有MBProgressHUD和SVProgressHUD
我覺得會一種就可以了,綜合前輩們的經驗選擇了後者,然後就花了一點時間,把他的方法都看了一下。在這裡用作記錄,供自己鞏固和查閱。
方法
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(@"執行完畢");
}];
}