前言:社會(huì)節(jié)奏很快,所以你也要跑的快一點(diǎn)
第三方框架中關(guān)于HUD有MBProgressHUD和SVProgressHUD
我覺得會(huì)一種就可以了,綜合前輩們的經(jīng)驗(yàn)選擇了后者,然后就花了一點(diǎn)時(shí)間,把他的方法都看了一下。在這里用作記錄,供自己鞏固和查閱。
方法
SVProgressHUD所以的方法都是類方法,并且對(duì)象是通過單例創(chuàng)建。由于方法都是通過類名調(diào)用,簡(jiǎn)單明了。
基本方法
+ (void)show; 顯示:狀態(tài)是一個(gè)迅速轉(zhuǎn)動(dòng)的圈
+ (void)showWithMaskType:(SVProgressHUDMaskType)maskType; 顯示并且?guī)е粋€(gè)狀態(tài)
+ (void)showWithStatus:(NSString*)status; 顯示并且?guī)е淖? + (void)showWithStatus:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
+ (void)showProgress:(float)progress; //顯示進(jìn)度:狀態(tài)是一個(gè)進(jìn)度圈
+ (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; //顯示消息信息,其實(shí)就是中心圖片更換了
+ (void)showInfoWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
+ (void)showSuccessWithStatus:(NSString*)string; //顯示成功消息
+ (void)showSuccessWithStatus:(NSString*)string maskType:(SVProgressHUDMaskType)maskType;
+ (void)showErrorWithStatus:(NSString *)string; //顯示錯(cuò)誤消息
+ (void)showErrorWithStatus:(NSString *)string maskType:(SVProgressHUDMaskType)maskType;
// use 28x28 white pngs
+ (void)showImage:(UIImage*)image status:(NSString*)status; //顯示自己設(shè)置的圖片,圖片大小事28 * 28 px
+ (void)showImage:(UIImage*)image status:(NSString*)status maskType:(SVProgressHUDMaskType)maskType;
+ (void)setOffsetFromCenter:(UIOffset)offset; //距離中心點(diǎn)的偏移量
+ (void)resetOffsetFromCenter; //返回中心點(diǎn)
+ (void)popActivity; // 消除一個(gè)HUD,根據(jù)其實(shí)現(xiàn)方法如果前面有執(zhí)行了好幾次show方法,如果給定的progress == 0 或者 pregress < 0那樣就會(huì)讓使一個(gè)參數(shù)+1,執(zhí)行這個(gè)方法會(huì)使那個(gè)參數(shù)-1,如果參數(shù)==0時(shí) 執(zhí)行dismiss方法。
+ (void)dismiss; 消失
+ (BOOL)isVisible; 是否正在顯示
關(guān)于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; //成功時(shí)的圖片 // default is the bundled success image provided by Freepik
+ (void)setErrorImage:(UIImage*)image; //失敗時(shí)的圖片 // default is the bundled error image provided by Freepik
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType; //當(dāng)HUD顯示時(shí),用戶是否可以點(diǎn)擊其他控件// default is SVProgressHUDMaskTypeNone
SVProgressHUDMaskTypeNone = 1, // 允許用戶進(jìn)行其他用戶操作
SVProgressHUDMaskTypeClear, // 不允許用戶進(jìn)行其他用戶操作
SVProgressHUDMaskTypeBlack, // 不允許用戶進(jìn)行其他用戶操作,并且背景是黑色的
SVProgressHUDMaskTypeGradient // 允許用戶進(jìn)行其他用戶操作,并且背景是漸變的黑色
+ (void)setViewForExtension:(UIView*)view; //可以延展一個(gè)圖片必須設(shè)置#define SV_APP_EXTENSIONS
關(guān)于HUD的通知
extern NSString * const SVProgressHUDDidReceiveTouchEventNotification; 在HUD外點(diǎn)擊
extern NSString * const SVProgressHUDDidTouchDownInsideNotification; 在HUD中點(diǎn)擊
extern NSString * const SVProgressHUDWillDisappearNotification; 將要顯示
extern NSString * const SVProgressHUDDidDisappearNotification; 已經(jīng)顯示
extern NSString * const SVProgressHUDWillAppearNotification; 將要消失
extern NSString * const SVProgressHUDDidAppearNotification; 已經(jīng)消失
extern NSString * const SVProgressHUDStatusUserInfoKey; HUD的狀態(tài)
在通知中userInfo字典中存儲(chǔ)了HUD的狀態(tài),其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];
});
*/
/**
* 實(shí)例方法
*/
MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
//顯示hud的模式
hud.mode = MBProgressHUDModeDeterminate;
//背景顏色
hud.color = [UIColor redColor];
//主標(biāo)題
hud.labelText = @"主標(biāo)題";
//副標(biāo)題
hud.detailsLabelText = @"副標(biāo)題";
//顯示、隱藏時(shí)的動(dòng)畫樣式
hud.animationType = MBProgressHUDAnimationZoomIn;
//當(dāng)mode的屬性是跟進(jìn)度相關(guān)時(shí),就可以設(shè)置progress的值,實(shí)現(xiàn)實(shí)時(shí)進(jìn)度的顯示
hud.progress = 0.8;
// HUD的相對(duì)于父視圖 x 的偏移,默認(rèn)居中
// hud.xOffset = 50;
// hud.yOffset = 50;
//是否顯示蒙板
hud.dimBackground = YES;
//HUD內(nèi)部視圖相對(duì)于HUD的內(nèi)邊距
hud.margin = 50;
//HUD的圓角半徑
hud.cornerRadius = 20;
//最小的顯示時(shí)間
hud.minShowTime = 3.0;
// HUD的最小尺寸
hud.minSize = CGSizeMake(300, 300);
// 代理中只有一個(gè)方法,即獲得HUD隱藏后的時(shí)刻
// hud.delegate = self;
[self.view addSubview:hud];
[hud showAnimated:YES whileExecutingBlock:^{
//hud執(zhí)行期間
NSLog(@"執(zhí)行期間");
} onQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) completionBlock:^{
//hud執(zhí)行完畢
NSLog(@"執(zhí)行完畢");
}];
}