SVProgressHUD源碼記一:ReadMe解讀

基本使用

SVProgressHUD 為單例對象,不要手動地實例化,直接使用[SVProgressHUD method]方式.

使用場景主要為執(zhí)行耗時任務時進行遮罩顯示或者簡單信息的提示來增加用戶體驗,比如下拉刷新、無限滾動、發(fā)送遠程消息.

    [SVProgressHUD show]; //顯示HUD
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        // time-consuming task 執(zhí)行耗時操作(常常為網(wǎng)絡訪問)
        dispatch_async(dispatch_get_main_queue(), ^{
            [SVProgressHUD dismiss]; // 消除HUD
        });
    });

顯示HUD

  • 針對任務的執(zhí)行狀態(tài)不確定時的HUD顯示

    + (void)show;
    + (void)showWithStatus:(NSString*)string;
    
  • 針對任務的執(zhí)行過程能進度表示的HUD顯示

    + (void)showProgress:(CGFloat)progress;
    + (void)showProgress:(CGFloat)progress status:(NSString*)status;
    

銷毀HUD

  • 簡單銷毀

    + (void)dismiss;
    + (void)dismissWithDelay:(NSTimeInterval)delay; // 延時銷毀
    
  • 批量HUD銷毀

    + (void)popActivity;
    
  • 快速顯示信息在HUD銷毀后,顯示時間0.5~5.0s間

    + (void)showInfoWithStatus:(NSString *)string;
    + (void)showSuccessWithStatus:(NSString*)string;
    + (void)showErrorWithStatus:(NSString *)string;
    + (void)showImage:(UIImage*)image status:(NSString*)string;
    

自定義

+ (void)setDefaultStyle:(SVProgressHUDStyle)style;                  // default is SVProgressHUDStyleLight HUD樣式設置
+ (void)setDefaultMaskType:(SVProgressHUDMaskType)maskType;         // default is SVProgressHUDMaskTypeNone HUD背景遮罩層設置
+ (void)setDefaultAnimationType:(SVProgressHUDAnimationType)type;   // default is SVProgressHUDAnimationTypeFlat HUD動畫類型設置
+ (void)setMinimumSize:(CGSize)minimumSize;                         // default is CGSizeZero, can be used to avoid resizing for a larger message HUD顯示文字信息的最小尺寸
+ (void)setRingThickness:(CGFloat)width;                            // default is 2 pt HUD圓環(huán)寬度設置
+ (void)setRingRadius:(CGFloat)radius;                              // default is 18 pt HUD圓環(huán)半徑設置
+ (void)setRingNoTextRadius:(CGFloat)radius;                        // default is 24 pt 無文本的圓環(huán)半徑設置
+ (void)setCornerRadius:(CGFloat)cornerRadius;                      // default is 14 pt
+ (void)setFont:(UIFont*)font;                                      // default is [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline] HUD文本字體設置
+ (void)setForegroundColor:(UIColor*)color;                         // default is [UIColor blackColor], only used for SVProgressHUDStyleCustom HUD前景色設置
+ (void)setBackgroundColor:(UIColor*)color;                         // default is [UIColor whiteColor], only used for  SVProgressHUDStyleCustom HUD背景色設置
+ (void)setInfoImage:(UIImage*)image;                              // default is the bundled info image provided by Freepik HUD內(nèi)容圖片設置
+ (void)setSuccessImage:(UIImage*)image;                            // default is bundled success image from Freepik HUD成功樣式的圖片設置
+ (void)setErrorImage:(UIImage*)image;                              // default is bundled error image from Freepik HUD錯誤樣式時圖片設置
+ (void)setViewForExtension:(UIView*)view;                       // default is nil, only used if #define SV_APP_EXTENSIONS is set 
+ (void)setMinimumDismissTimeInterval:(NSTimeInterval)interval;     // default is 5.0 seconds HUD銷毀的最短時間設置
  • 支持UIAppearance協(xié)議方法,能夠同一配置.

提示

SVProgressHUD提供兩種配置好的樣式

  • SVProgressHUDStyleLight: 白色背景,黑色圓環(huán)和文字
  • SVProgressHUDStyleDark: 黑色背景,白色圓環(huán)和文字
  • 若要自定義必須先設setDefaultStyleSVProgressHUDStyleCustom,再進行setForegroundColor,setBackgroundColor的配置.

通知監(jiān)聽

SVProgressHUD提供了四個通知方法,來對應當HUD出現(xiàn)和銷毀時.

  • SVProgressHUDWillAppearNotification 當HUD顯示動畫開始時
  • SVProgressHUDDidAppearNotification 當HUD已經(jīng)顯示
  • SVProgressHUDWillDisappearNotification 當HUD銷毀動畫開始時
  • SVProgressHUDDidDisappearNotification 當HUD已經(jīng)銷毀

其通知的userinfo字典存儲了HUD的狀態(tài),其key
SVProgressHUDStatusUserInfoKey.

SVProgressHUD還有SVProgressHUDDidReceiveTouchEventNotificationSVProgressHUDDidReceiveTouchEventNotification兩個通知檢測用戶對HUD的交互,它們的userinfo為空,但其objectUIEvent對象.

App擴展

在App擴展中使用SVProgressHUD時,需要用到#define SV_APP_EXTENSIONS避免使用到不可用的API,另外在擴展控制器中針對self.view調(diào)用setViewForExtension.

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 有段時間沒有寫了。這個周末抽空簡單整理了一下關于自己對SVProgressHUD一些看法以及感悟。過程中自己感受到...
    紙簡書生閱讀 39,616評論 39 224
  • SVProgressHUD是iOS開發(fā)中比較常用的一個三方庫,用來在執(zhí)行耗時操作或者指示用戶操作結果的場合,由于使...
    飛魚灣閱讀 1,812評論 0 0
  • 源碼來源:gitHub源碼 轉載于: CocoaChina 來源:南峰子的技術博客 版本:0.9.1 MBPr...
    李小六_閱讀 6,555評論 2 5
  • 在iOS開發(fā)中不可避免的會用到一些第三方類庫,它們提供了很多實用的功能,使我們的開發(fā)變得更有效率;同時,也可以從它...
    蘇哲炫爺閱讀 1,115評論 0 0
  • 【微公益】【856】【每日經(jīng)典】【20170828莊子066】 今日實不得便,只能現(xiàn)在寫完發(fā)出,總算沒有遺漏一日。
    北冥_鯤閱讀 232評論 0 4

友情鏈接更多精彩內(nèi)容